描述:某次更新程序,需要给测试员MM测试,之前都是正常的,更新后给MM测试就报异常System.Net.WebException 无法从传输连接读取数据:连接已关闭 -------> System.IO.IOException:
无法从传输连接中读取数据:你的主机中的软件中止了一个已建立的连接。
我在控制台应用程序中有这个代码,它运行在一个循环中
</>code
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search);
- request.Headers.Add("Accept-Language","de-DE");
- request.Method = "GET";
- request.Accept = "text/html";
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- {
- using (StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding.ASCII))
- {
- string html = reader.ReadToEnd();
- FindForMatch(html,url);
- }
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
Unable to read data from the transport connection: The connection was closed
错误.任何想法为什么会这样?感谢名单..
加入后
</>code
- request.KeepAlive = false;
- request.ProtocolVersion = HttpVersion.Version10;
它工作正常..
我发现它形成这个博文
WebRequest and Unable to read data from the transport connection Error
以上为你收集整理的c# – 无法从传输连接读取数据:控制台应用程序中的连接已关闭错误全部内容,希望文章能够帮你解决c# – 无法从传输连接读取数据:控制台应用程序中的连接已关闭错误所遇到的程序开发问题。
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛