HTTP POST返回错误:417"预期失败"。 [英] HTTP POST Returns Error: 417 "Expectation Failed."

查看:681
本文介绍了HTTP POST返回错误:417"预期失败"。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试发布它导致以下异常的网址:

When I try to POST to a URL it results in the following exception:

远程服务器返回错误:
  (417)预期失败。

The remote server returned an error: (417) Expectation Failed.

下面是一个示例code:

Here's a sample code:

var client = new WebClient();

var postData = new NameValueCollection();
postData.Add("postParamName", "postParamValue");

byte[] responseBytes = client.UploadValues("http://...", postData);
string response = Encoding.UTF8.GetString(responseBytes); // (417) Expectation Failed.

使用的HttpWebRequest / HttpWebResponse 对或的HttpClient 不有所作为。

是什么造成这个异常?

推荐答案

System.Net.HttpWebRequest添加页眉HTTP头期望:100-继续'的每一个请求,除非你明确要求它不要通过设置<一个href=\"http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue(VS.80).aspx\">this静态属性为false:

System.Net.HttpWebRequest adds the header 'HTTP header "Expect: 100-Continue"' to every request unless you explicitly ask it not to by setting this static property to false:

System.Net.ServicePointManager.Expect100Continue = false;

某些服务器噎死的头以及发回的417错误你看到。

Some servers choke on that header and send back the 417 error you're seeing.

把那一个镜头。

这篇关于HTTP POST返回错误:417&QUOT;预期失败&QUOT;。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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