Web客户端和expect100continue [英] webclient and expect100continue

查看:250
本文介绍了Web客户端和expect100continue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是使用Web客户端(C#.NET)时设置expect100continue的最佳途径。我有这样的代码下面,我仍然看到100继续在头部。 。愚蠢的Apache还是会抱怨有505误差

What is the best way to set expect100continue when using WebClient(C#.NET). I have this code below, I still see 100 continue in the header. Stupid apache still complains with 505 error.

        string url = "http://aaaa.com";
        ServicePointManager.Expect100Continue = false;

        WebClient service = new WebClient();           
        service.Credentials = new NetworkCredential("username", "password");
        service.Headers.Add("Content-Type","text/xml");

        service.UploadStringCompleted += (sender, e) => CompleteCallback(BuildResponse(e));
        service.UploadStringAsync(new Uri(url), "POST", query);

请注意:如果我把上面的控制台应用程序,并让它运行 - 那么我看不到标题中的小提琴手。但是,我的代码被嵌入在由一个WPF应用程序加载的用户库。那么,有没有更多的Expect100Continue螺纹,初始化等方面现在,我觉得它更我的代码的问题。

Note: If I put the above in a console app and let it run - then I do not see the headers in fiddler. But, my code is embedded in a user library which is loaded by a WPF app. So, Is there more to Expect100Continue in terms of thread, initialization, etc. Now, I think it is more of my code issue.

推荐答案

您需要设置在 Expect100Continue 属性的ServicePoint 用于您所访问的网址:

You need to set the Expect100Continue property on the ServicePoint used for the URI you're accessing:

var uri = new Uri("http://foo.bar.baz");
var servicePoint = ServicePointManager.FindServicePoint(uri);
servicePoint.Expect100Continue = false;

这篇关于Web客户端和expect100continue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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