c# 基础连接已经关闭: 连接被意外关闭,错误的解决

调试一个使用HttpWebRequest模拟提交表单的程序的时候频繁出现上述错误提示,google了一下发现了几个解决方案。
1、在application.config或web.config文件里加入

<system.net> 
<settings> 
<httpWebRequest useUnsafeHeaderParsing="true"/> 
</settings> 
</system.net>

2、设置clientConnectionLimit属性需要在客户端的 .config 文件当中:
如:

<system.runtime.remoting> 
<application> 
<channels> 
<channel ref="http" clientConnectionLimit="50"> 
<clientProviders> 
<formatter ref="soap" /> 
</clientProviders> 
</channel> 
</channels> 
</application> 
</system.runtime.remoting>

这两种方法都没能解决我的问题,突然看到有人提到headers信息的问题,增加一句代码

MyRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"; 

问题解决 

原文地址:https://www.cnblogs.com/chengulv/p/2922955.html