The underlying connection was closed: An unexpected error occurred on a receive
- by Dave
Using a console app which runs as a scheduled task on Azure, to all a long(ish) running webpage on Azure.
Problem after a few minutes: The underlying connection was closed: An unexpected error occurred on a receive
//// 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);
}
}
}