如何禁用“期望:100继续" HttpWebRequest中的标头是否有单个请求? [英] How to disable the "Expect: 100 continue" header in HttpWebRequest for a single request?
问题描述
HttpWebRequest
自动为POST请求附加Expect: 100-continue
标头.互联网上的各种消息表明,可以按以下方式禁用此功能:
HttpWebRequest
automatically appends an Expect: 100-continue
header for POST requests. Various sources around the internet suggest that this can be disabled as follows:
System.Net.ServicePointManager.Expect100Continue = false;
但是,我正在编写一个库,并且如果应用程序依赖于此行为,则无法为整个appdomain禁用它.我也不能假设它将保持设置为该值.如何针对特定请求将其禁用?
However, I'm writing a library and I cannot disable this for the entire appdomain, in case the application relies on this behaviour. Nor can I assume that it will remain set to this value. How can I disable it for a specific request?
推荐答案
HttpWebRequest
类具有一个名为ServicePoint
的属性,可用于更改特定请求的此设置.例如:
The HttpWebRequest
class has a property called ServicePoint
which can be used to change this setting for a specific request. For example:
var req = (HttpWebRequest) WebRequest.Create(...);
req.ServicePoint.Expect100Continue = false;
这篇关于如何禁用“期望:100继续" HttpWebRequest中的标头是否有单个请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!