Dar*_*ana 11 c# console-application httpwebrequest streamreader
我在控制台应用程序中有这个代码,它在一个循环中运行
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);
}
Run Code Online (Sandbox Code Playgroud)
经过几次循环就给出了
无法从传输连接读取数据:连接已关闭
错误.知道为什么会这样吗?感谢名单..
Dar*_*ana 23
添加后
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
Run Code Online (Sandbox Code Playgroud)
它工作正常..
我发现它来自这篇博文