0

I have encountered a strange problem when using HttpClient,the code show below.

  • Environment: k8s
  • Internet: intranet
  • App: .NET Core 3.1

Code:

using (var httpClient = new HttpClient())
{
    httpClient.Timeout = new TimeSpan(2, 0, 0);
    using var httpContent = new StringContent(JsonConvert.SerializeObject(exportParameter), Encoding.UTF8, "application/json");
    var httpResponseMessage = await httpClient.PostAsync($"{url}", httpContent);
}

This is a file export scene, if it's a small file export (the response is very fast, less than 5 minutes, most of this scene) -- never had any problems.

But when we perform a large file export(the response size is about 100MB and waiting time is more than one hour but less than two hours), the httpclient requester will prompt

The application aborted the connection

and the httpclient gets no response.

Does anyone know what is causing the problem?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AlexYIN
  • 1
  • 1
  • It could be many things I've found that changing the code path to fully sync sometimes helps (like in that question) https://stackoverflow.com/questions/57008670/connection-closing-while-downloading-extremely-large-file but it doesn't explain anything. What happens with your application when you're making the request? Are the Out Of Memory situations possible? What happens with the application that gives you response? What if you try to ping the server you're getting your file from, does it respond correctly? What about network lags? Who aborts the request? It can be complicated – HaroldMorgan Feb 15 '22 at 13:45
  • Use [HTTP ranges](https://weblog.west-wind.com/posts/2004/Feb/07/Using-HTTP-Ranges-to-resume-resume-aborted-downloads) for large files so you can resume aborted downloads – johnny 5 Feb 15 '22 at 15:30

0 Answers0