我在控制台应用程序中有这个代码,它运行在一个循环中
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
错误.任何想法为什么会这样?感谢名单..
解决方法
加入后
request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10;
它工作正常..
我发现它形成这个博文
WebRequest and Unable to read data from the transport connection Error