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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14595021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:22:25  来源:igfitidea点击:

How to disable the “Expect: 100 continue” header in WinRT's HttpWebRequest

c#windows-8httpwebrequestwindows-runtime

提问by DVD

I'm developing an app that for legacy code reasons I can't upgrade for the new HttpClientso I'm using HttpWebRequests.

我正在开发一个应用程序,由于遗留代码的原因我无法升级新的,HttpClient所以我使用HttpWebRequests.

In .NET 4 we could deactivate the Expect header (on posts requests) using ServicePoint.Expect100Continueproperty, 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.Expect100Continueis not available either.

编辑:System.Net.ServicePointManager.Expect100Continue也不可用。

回答by Radin Gospodinov

It seems the only option you have it to override BeginGetRequestStream. HttpWebRequest has a private method MakeRequest and in it the Expect100Continue header is added to the request header collection.

它似乎是您覆盖 BeginGetRequestStream 的唯一选择。HttpWebRequest 有一个私有方法 MakeRequest,其中 Expect100Continue 标头被添加到请求标头集合中。

回答by Flatliner DOA

        var c = new HttpClient();
        c.DefaultRequestHeaders.ExpectContinue = false;

回答by 8bitcat

Put this is your webconfig.

把这是你的webconfig。

 <system.net>
 <settings>?
 <servicePointManager expect100Continue="false"/>??
 </settings>?
 </system.net>

Also works! I use this in my webapplication. But answer above is equally as good!

也有效!我在我的网络应用程序中使用它。但上面的答案同样好!