无法从传输连接中读取数据:控制台应用程序中的连接已关闭错误 [英] Unable to read data from the transport connection: The connection was closed error in console application
本文介绍了无法从传输连接中读取数据:控制台应用程序中的连接已关闭错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在控制台应用程序中有此代码,并且它循环运行
I have this code in console application and it runs in a loop
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
错误。知道为什么会这样吗? thanx ..
error. any idea why this happen? thanx..
推荐答案
添加后
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
工作正常。
I在博客中找到它
这篇关于无法从传输连接中读取数据:控制台应用程序中的连接已关闭错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文