c# – 无法从传输连接读取数据:控制台应用程序中的连接已关闭错误

c# – 无法从传输连接读取数据:控制台应用程序中的连接已关闭错误,第1张

概述我在控制台应用程序中有这个代码,它运行在一个循环中 try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search); request.Headers.Add("Accept-Language", "de-DE"); request.Method = "GET"; re 我在控制台应用程序中有这个代码,它运行在一个循环中
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

总结

以上是内存溢出为你收集整理的c# – 无法从传输连接读取数据:控制台应用程序中的连接已关闭错误全部内容,希望文章能够帮你解决c# – 无法从传输连接读取数据:控制台应用程序中的连接已关闭错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1262996.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-08
下一篇2022-06-08

发表评论

登录后才能评论

评论列表(0条)

    保存