Click here to Skip to main content
15,067,251 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have two API created in .net core 3.1 (lets say api A & api B) api A will call api B and merging 2 out put.But when call, I am getting :"Error:: Exception has been thrown by the target of an invocation.: Error Executing C# Script"

so as I said I have 2 apis are running different port api A and api B.

I need to get the result from api A to api B. so In my api a has the combination of api A and api B. I am using the same request for both.

the problem is when I call a external api call to api B from api B. But it works when I run api B only. I don't understand the issue

What I have tried:

in api B
C#
public async Task GetKeyData(string key){
    string dataKey = string.Empty;
    var requestUri = string.Format("{0}/{1}", _KeyUri, key);
    HttpClient client = new HttpClient(new HttpClientHandler() { 
        UseDefaultCredentials = true });
    
    client.DefaultRequestHeaders.Accept.Add(new 
        MediaTypeWithQualityHeaderValue("application/json"));
    
    var rawData = await client.GetAsync(requestUri);
    
    // below  line are getting error when i call from api A to this 
    var jsonResponse = await rawData.Content.ReadAsStringAsync();//error showing here
    string value = JsonConvert.DeserializeObject(jsonResponse);
    
     //balance code
}

What mistake I am doing here?
Posted
Updated 23-Jun-21 22:25pm
v2
Comments
Member 15263415 26-Jun-21 5:27am
   
var jsonResponse = await rawData.Content.ReadAsStringAsync(); cheeck this code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900