当前位置: 移动技术网 > IT编程>开发语言>c# > C# httpwebrequest访问HTTPS错误处理方法

C# httpwebrequest访问HTTPS错误处理方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

c# httpwebrequest访问https链接时遇到这个错误,但是如果我开抓包工具,比如filddler2,则post返回正常

错误提示的message为:

基础连接已经关闭: 发送时发生错误。

innerexception为:

从传输流收到意外的 eof 或 0 个字节。

试了网上的n种方法,以下是本次的解决方案:

servicepointmanager.securityprotocol = securityprotocoltype.ssl3;

把网上找到的解决方案列一下,没准就能解决了你的问题

以下是网上找到的解决方案:

1. request.protocolversion = httpversion.version10;

2. servicepointmanager.servercertificatevalidationcallback = new remotecertificatevalidationcallback(checkvalidationresult);

3.servicepointmanager.securityprotocol = securityprotocoltype.tls;

4.换个useragent试试

5.在app.config中添加以下内容:

<system.net>
  <settings>
   <httpwebrequest useunsafeheaderparsing="true"/>
  </settings>
 </system.net>

以上这篇c# httpwebrequest访问https错误处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网