0

这是下载代码:

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;
        }

例外是在线:

response = request.GetResponse();

这是例外:

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: 

可能是什么问题呢 ?我每 n 秒从网站下载 ocntent。到目前为止,大多数时候都没有问题,我只遇到过一次这个异常。

第 112 行是:

string content = downloadContent();

第 228 行是:

response = request.GetResponse();
4

1 回答 1

0

(502) Bad Gateway 可能意味着远程服务器出现问题(站点关闭、服务器重新启动等)

来自http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

10.5.3 502 Bad Gateway

The server, while acting as a gateway or proxy, received an invalid response from the 
upstream server it accessed in attempting to fulfill the request.
于 2012-08-13T23:59:59.290 回答