[英]How to disable the “Expect: 100 continue” header in WinRT's HttpWebRequest
I'm developing an app that for legacy code reasons I can't upgrade for the new HttpClient
so I'm using HttpWebRequests
. 我正在开发一个应用程序,由于遗留代码的原因我无法升级为新的HttpClient
因此我正在使用HttpWebRequests
。
In .NET 4 we could deactivate the Expect header (on posts requests) using ServicePoint.Expect100Continue
property, but on WinRT it's not available. 在.NET 4中,我们可以使用ServicePoint.Expect100Continue
属性停用Expect标头(在帖子请求上),但在WinRT上它不可用。
How can this be accomplished on WinRT? 如何在WinRT上完成?
EDIT: System.Net.ServicePointManager.Expect100Continue
is not available either. 编辑: System.Net.ServicePointManager.Expect100Continue
也不可用。
var c = new HttpClient();
c.DefaultRequestHeaders.ExpectContinue = false;
Put this is your webconfig. 把它放在你的webconfig中。
<system.net>
<settings>
<servicePointManager expect100Continue="false"/>
</settings>
</system.net>
Also works! 也有效! I use this in my webapplication. 我在我的webapplication中使用它。 But answer above is equally as good! 但上面的回答同样好!
It seems the only option you have it to override BeginGetRequestStream. 它似乎是唯一一个覆盖BeginGetRequestStream的选项。 HttpWebRequest has a private method MakeRequest and in it the Expect100Continue header is added to the request header collection. HttpWebRequest有一个私有方法MakeRequest,其中Expect100Continue头被添加到请求头集合中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.