gpt4 book ai didi

c# - 无法从传输连接读取数据 : The connection was closed error in console application

转载 作者:可可西里 更新时间:2023-11-01 08:39:46 26 4
gpt4 key购买 nike

我在控制台应用程序中有这段代码,它在一个循环中运行

 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# - 无法从传输连接读取数据 : The connection was closed error in console application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11323584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com