Sujeet Raman

Sujeet Raman

  • 793
  • 915
  • 330.6k

Tthe response ended prematurely. c# httpclient-What does it mean?

Jun 24 2021 5:10 AM

UPDATE:the response ended prematurely. c# httpclient  -now i am getting this error in another mtd which is also an external call

I am getting Error:"Error:: Exception has been thrown by the target of an invocation.: Error Executing C# Script"

i have 2 api ,s are running diffrent 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 abi 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 dont understand the issue

in api B

public async Task GetKeyData(string key)
{
    string dataKey = string.Empty;
    try
    {
        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 2 lines are getting error when i call from api A to this 
        var jsonResponse = await rawData.Content.ReadAsStringAsync();
        string value = JsonConvert.DeserializeObject(jsonResponse);
        //balance code
    }
}

 


Answers (1)