gpt4 book ai didi

c# - 底层连接已关闭: An unexpected error occurred on a receive

转载 作者:行者123 更新时间:2023-12-02 08:10:47 25 4
gpt4 key购买 nike

使用在 Azure 上作为计划任务运行的控制台应用程序来处理 Azure 上所有长时间运行的网页。

几分钟后出现问题:底层连接已关闭:接收时发生意外错误

 //// used as WebClient doesn't support timeout
public class ExtendedWebClient : WebClient
{
public int Timeout { get; set; }

protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
if (request != null)
request.Timeout = Timeout;
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
return request;
}

public ExtendedWebClient()
{
Timeout = 1000000; // in ms.. the standard is 100,000
}
}

class Program
{
static void Main(string[] args)
{
var taskUrl = "http://www.secret.com/secret.aspx";
// create a webclient and issue an HTTP get to our url
using (ExtendedWebClient httpRequest = new ExtendedWebClient())
{
var output = httpRequest.DownloadString(taskUrl);
}
}
}

最佳答案

请注意,Windows Azure 负载平衡器会在 60 秒后终止空闲 TCP 连接。看起来您正在通过负载均衡器进行调用...是否有可能该操作花费的时间超过 60 秒而没有发送任何内容?

关于c# - 底层连接已关闭: An unexpected error occurred on a receive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6419924/

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