使用在Azure上作爲計劃任務運行的控制檯應用程序在Azure上運行的所有長(ish)網頁。幾分鐘後底層連接已關閉:接收時發生意外錯誤
問題:基礎連接已關閉:意外出錯一個接收
//// 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);
}
}
}
沒有完全解決..但要去一個控制檯應用程序。 –