HttpClient PostAsJsonAsync Disble KeepAlive

时间:2014-08-08 15:27:39

标签: .net dotnet-httpclient

我正在使用HttpClient向ASP.NET WEB API发出POST请求。 我想禁用Keep Alive连接。

如何禁用活着?

1 个答案:

答案 0 :(得分:1)

您可以显式创建HttpWebRequest并将其KeepAlive属性设置为false:

string url = "" //Add your url here

HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.KeepAlive = false;

var httpClient = new HttpClient();
httpClient.SendAsync(request);

HttpClient为您创建HttpWebRequest。但是,当你想对所提出的请求进行更细粒度的控制时,你仍然必须自己生成它。