请求http状态404失败
When using WebServices and calling some Web Methods, you may come across to this exception:
使用WebServices并调用某些Web方法时,可能会遇到此异常:
The request failed with HTTP status 417: Expectation failed.When Expect 100-Continue property is set to true (this is actually set within part of the .Net framework, which makes this a difficult problem to overcome. You have to override this in more than one place), this 417 error occurs when the proxy server doesn't support 100-Continue.
请求失败,HTTP状态为417:期望失败。当Expect 100-Continue属性设置为true(这实际上是在.Net框架的一部分中设置的,这使这成为一个难以克服的问题。您必须在多个地方覆盖它),当代理服务器不支持100-继续。
In the case of expect 100-Continue, the client will expect to receive a 100-Continue response from the server to indicate that the client should send the data to be posted. This mechanism allows clients to avoid sending large amounts of data over the network when the server, based on the request headers, intends to reject the request.
在期望100继续的情况下,客户端将期望从服务器收到100继续响应,以指示客户端应发送要发布的数据。 当服务器基于请求标头打算拒绝该请求时,该机制允许客户端避免通过网络发送大量数据。
The Expect 100-Continue behavior is fully described in IETF RFC 2616 Section 10.1.1.
IETF RFC 2616第10.1.1节中完整描述了Expect 100-Continue行为。
You can also read more about it in MSDN.
您也可以在MSDN中阅读有关它的更多信息。
To workaround this exception you can do a simple thing: Disable expect 100 continue.
要解决此异常,您可以做一个简单的事情:禁用期望继续100。
So you may ask how to disable expect 100 continue?
因此,您可能会问如何禁用期望100继续?
Warning: When you disable Expect 100-Continues and your application sends a large amount of data on the network, if for any reason the server rejects your request, you have to re-send the entire data again, this may cause some extra traffic in your network. Also multiple calls to a server will take longer, since each call will wait until the prior call's response is received.
警告:当您禁用Expect 100-Continues且您的应用程序在网络上发送了大量数据时,如果服务器出于某种原因拒绝了您的请求,则您必须再次重新发送整个数据,这可能会导致您的网络。 同样,多次呼叫服务器将花费更长的时间,因为每个呼叫都将等待直到收到前一个呼叫的响应。
It is easy, here are two alternative ways:
这很容易,这里有两种替代方法:
1) We need to have this line of code before making any web requests.
1)在发出任何Web请求之前,我们需要具有以下代码行。
System.Net.ServicePointManager.Expect100Continue = false;
2) Add these lines to the application's configuration file (between and ):
2)将这些行添加到应用程序的配置文件中(和之间):
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
While this workaround is nice, I think a better long term solution is to upgrade/replace the proxy server to handle 100-continue calls.
尽管此解决方法不错,但我认为更好的长期解决方案是升级/替换代理服务器以处理100个继续的呼叫。
So far in this short tip we've learned what is Expect 100, how it is caused and how to workaround this expectation.
到目前为止,我们已经了解了什么是Expect 100,它是如何引起的以及如何解决此期望。
请求http状态404失败