这是下载代码:
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();