如何禁用“期望:100继续" HttpWebRequest中的标头是否有单个请求? [英] How to disable the "Expect: 100 continue" header in HttpWebRequest for a single request?

查看:119
本文介绍了如何禁用“期望:100继续" HttpWebRequest中的标头是否有单个请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆