[英]Expect: 100-continue
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
.根据建议 - 有一个设置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.有一些建议如何设置它,但它似乎不起作用。
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” - header Expect: 100-continue
仍然被添加,但它不应该根据我在这里阅读的建议: C# Expect100Continue header request 。
You can do it this way :你可以这样做:
_request.ServicePoint.Expect100Continue = false;
This will disable the Expect: 100-continue
for a particular HttpWebRequest
instance.这将禁用特定HttpWebRequest
实例的Expect: 100-continue
。
When this property is set to true, client requests that use the POST method expect to receive a 100-Continue response from the server to indicate that the client should send the data to be posted.当此属性设置为 true 时,使用 POST 方法的客户端请求期望从服务器接收 100-Continue 响应,以指示客户端应发送要发布的数据。 This mechanism allows clients to avoid sending large amounts of data over the network when the server, based on the request headers, intends to reject the request.当服务器根据请求标头打算拒绝请求时,此机制允许客户端避免通过网络发送大量数据。
ServicePointManager.Expect100Continue = true; ServicePointManager.Expect100Continue = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.