I send HTTP request with the MultipartFormDataContent
but I'm getting the following error when the file size is more than 2mb:
Error while copying content to a stream.
Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
An existing connection was forcibly closed by the remote host.
But exactly the same request with more than 5mb file can be sent with PostMan successfully.
This is my code:
using (var client = new HttpClient(GetHttpClientHandler(requestUrl)))
{
using (var content = new MultipartFormDataContent())
{
for (int i = 0; i < images.Count; i++)
{
var fileName = $"file {(i + 1)}.png";
ByteArrayContent bContent = new ByteArrayContent(images[i]);
content.Add(bContent, "file", fileName);
}
using (var response = await client.PostAsync(requestUrl, content)) //Exception occurs here
{
resp = await response.Content.ReadAsStringAsync();
response.EnsureSuccessStatusCode();
}
}
}
So, if the problem about the server-side why it works with PostMan? If the problem is in my code, what is that then? I think I did everything by convention.