This is the download code:
private string downloadContent()
{
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
response = request.GetResponse();
Stream stream = response.GetResponseStream();
reader = new StreamReader(stream);
string content = reader.ReadToEnd();
return content;
}
The exception was on the line:
response = request.GetResponse();
This is the Exception:
system.Net.WebException was unhandled by user code
Message=The remote server returned an error: (502) Bad Gateway.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at ChatrollLogger.Form1.downloadContent() in D:\C-Sharp\ChatrollLogger\ChatrollLogger\ChatrollLogger\Form1.cs:line 228
at ChatrollLogger.Form1.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in D:\C-Sharp\ChatrollLogger\ChatrollLogger\ChatrollLogger\Form1.cs:line 112
at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
InnerException:
What could be the problem ? Im downloading the ocntent from the site each n seconds.
Most of the times no problems so far i got this exception once only.
Line 112 is:
string content = downloadContent();
And line 228 is:
response = request.GetResponse();
(502) Bad Gateway could mean that the remote server is having trouble (site down, server being restarted etc)
From http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html: