C#中POST请求时出现System.Net.WebException: 远程服务器返回错误: (417)Expectation Failed的解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pan_junbiao/article/details/82826993

在使用POST请求的时候,当要POST的数据大于1024字节的时候,服务不会直接就发起POST请求,而是会分为俩步:
(1)发送一个请求, 包含一个Expect:100-continue, 询问Server使用愿意接受数据。
(2)接收到Server返回的100-continue应答以后,才把数据POST给Server。

C#中的错误提示:System.Net.WebException: 远程服务器返回错误: (417)Expectation Failed。

解决办法:

1、在配置文件中的<configuration>节点里添加如下配置信息(推荐)

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

2、在执行代码中添加如下代码。

System.Net.ServicePointManager.Expect100Continue = false;

猜你喜欢

转载自blog.csdn.net/pan_junbiao/article/details/82826993