作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用在 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/
我是一名优秀的程序员,十分优秀!