While downloading some content from a website after few times i got exception webexception 502 Bad gateway what could make that?
<p>This is the download code:</p>

<pre><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;
        }
</code></pre>

<p>The exception was on the line:</p>

<pre><code>response = request.GetResponse();
</code></pre>

<p>This is the Exception:</p>

<pre><code>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: 
</code></pre>

<p>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.</p>

<p>Line 112 is: </p>

<pre><code>string content = downloadContent();
</code></pre>

<p>And line 228 is:</p>

<pre><code>response = request.GetResponse();
</code></pre>
