Hi @NicoZhu-MSFT ,
Thank you so much for your reply. I haven't added the
Keep-Alive
to
client.DefaultRequestHeaders.Connection
.
This is probably helpful.
Is it required for a request that has a long responding time(more than 4 minutes)? The problem is that it internally resending data to the server multiple times on users' environment, however, it doesn't happen in our environment.
Please see my code below,
class RequestTest
{
public async void Start()
{
Log.Trace("\n\nTest: Started");
try
{
string url = "http://server_url";
IProgress<HttpProgress> progress = new Progress<HttpProgress>(OnProgressChanged);
CancellationTokenSource cts = new CancellationTokenSource();
HttpClient httpClient = new HttpClient();
var httpRequestMsg = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
long delay = 10 * 1000 * 60;
string data = $"name=myname&delay={delay}";
httpRequestMsg.Method = HttpMethod.Post;
httpRequestMsg.Content = new HttpStringContent(data);
httpRequestMsg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded");
Log.Trace($"Delay time: {data}");
var response = await httpClient.SendRequestAsync(httpRequestMsg).AsTask(cts.Token, progress);
if (response.StatusCode == HttpStatusCode.Ok)
{
var res = await response.Content.ReadAsStringAsync();
Log.Trace(res);
}
}
catch (Exception ex)
{
Log.Error("\nException Message: \n", ex);
}
Log.Trace("\n\nTest: End");
}
private void OnProgressChanged(HttpProgress progress)
{
//Log progress
//HttpClientRequest.LogHttpProgress(progress);
}
}