C# 期望:100-继续
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15341287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expect: 100-continue
提问by Hikiko
There are a lot of questions on this topic, but - they gave me no answer.
关于这个话题有很多问题,但是 - 他们没有给我答案。
As from advices - there is one to set ServicePointManager.Expect100Continue = false
. But it is not acceptable because this will be a module, asynchroniously working along with dozen of others. So acceptable solution - is per-connection property. There are advices how to set this, but it doesn't seem to be working.
根据建议 - 有一个要设置ServicePointManager.Expect100Continue = false
。但这是不可接受的,因为这将是一个模块,与其他十几个异步工作。所以可接受的解决方案 - 是每个连接属性。有一些建议如何设置它,但它似乎不起作用。
Here is the code:
这是代码:
var conuri = new Uri(connectionString);
var sp = ServicePointManager.FindServicePoint(conuri);
sp.Expect100Continue = false;
_request = (HttpWebRequest)WebRequest.Create(conuri);
_request.ContentType = "text/xml";
_request.Method = "POST";
_request.ContentLength = dataToSend.Length;
requestStream = _request.GetRequestStream();
requestStream.Write(dataToSend, 0, dataToSend.Length);
Problem is, that at the point "requestStream.Write" - header Expect: 100-continue
is still added, but it shouldn't according to advice I've read here: C# Expect100Continue header request.
问题是,在这一点上,“requestStream.Write” -Expect: 100-continue
仍然添加了标头,但它不应该根据我在这里阅读的建议:C# Expect100Continue header request。
采纳答案by Parimal Raj
You can do it this way :
你可以这样做:
_request.ServicePoint.Expect100Continue = false;
This will disable the Expect: 100-continue
for a particular HttpWebRequest
instance.
这将禁用Expect: 100-continue
特定HttpWebRequest
实例的 。