作者:飘泊的牛小盆友 | 来源:互联网 | 2022-12-21 13:19
使用Microsoft Message Analyzer,我可以看到使用HttpClient发布的数据是以两个tcp数据包发送的.一个用于标题,然后一个用于发布数据.这些数据很容易适合一个数据包,但它被分成两个.我明确地打开了唠叨,并期望100继续使用ServicePointManager,但它似乎没有帮助.
ServicePointManager.Expect100COntinue= false;
ServicePointManager.UseNagleAlgorithm = true;
5023(.Net)显示2个数据包被发送到目的地,8170(邮递员)显示1个数据包被发送.测试是使用相同的有效负载完成的.
下面是一些用于在.net中生成请求的示例代码
public void TestRequest()
{
var uri = new Uri("http://www.webscantest.com/");
ServicePointManager.Expect100COntinue= false;
ServicePointManager.UseNagleAlgorithm = true;
var p = ServicePointManager.FindServicePoint(uri);
p.Expect100COntinue= false;
p.UseNagleAlgorithm = true;
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Connection", "close");
var values = new Dictionary
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var cOntent= new FormUrlEncodedContent(values);
var respOnse= client.PostAsync("http://www.webscantest.com/", content, CancellationToken.None).Result;
}
有没有办法强制有效载荷成为一个数据包?
使用.Net Framework 4.7
相关问题在这里