简体   繁体   English

如何在WinRT的HttpWebRequest中禁用“Expect:100 continue”标头

[英]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.

相关问题 "如何为单个请求禁用 HttpWebRequest 中的“期望:100 继续”标头?" - How to disable the "Expect: 100 continue" header in HttpWebRequest for a single request? 当 Expect100Continue header 被禁用时,HttpWebRequest 会引入显着延迟 - HttpWebRequest introduces significant latency when the Expect100Continue header is disabled 如何在Windows应用商店应用中使用WCF时禁用Expect:100-Continue - How to disable Expect:100-Continue when using WCF in Windows Store App 期望:100-继续 - Expect: 100-continue C#Expect100Continue标头请求 - C# Expect100Continue header request webclient 和 expect100continue - webclient and expect100continue 如何使用PCL的HttpWebRequest禁用AllowAutoRedirect - How to disable AllowAutoRedirect with PCL's HttpWebRequest 如何在编码的Visual Studio 2013 WebTestRequest上将Expect100Continue设置为false? - How does one set Expect100Continue to false on a Coded Visual Studio 2013 WebTestRequest? HttpWebRequest 与 HttpClient:处理 HTTP 100:继续在 HttpClient 中导致异常,但在 HttpWebRequest 中没有 - HttpWebRequest versus HttpClient: Handling of HTTP 100: Continue causes exception in HttpClient but not in HttpWebRequest Windows Store应用程序的ServicePoint.Expect100Continue - ServicePoint.Expect100Continue for Windows Store Apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM