我正在使用此代码给我发出问题
WebRequest req = WebRequest.Create("url");
StreamReader sr =new StreamReader(req.GetResponse().GetResponseStream());
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string strLine;
// Read the stream a line at a time and place each one into the stringbuilder
while ((strLine = sr.ReadLine()) != null)
{
// Ignore blank lines
if (strLine.Length > 0) sb.Append(strLine);
}
sr.Close();
lbl.Text= sb.ToString();
我收到此错误
The remote server returned an error: (503) Server Unavailable
答案 0 :(得分:1)
WebRequest req = WebRequest.Create(“http://www.google.com”); StreamReader sr = new StreamReader(req.GetResponse()。GetResponseStream());
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string strLine;
// Read the stream a line at a time and place each one into the stringbuilder
while ((strLine = sr.ReadLine()) != null)
{
// Ignore blank lines
if (strLine.Length > 0) sb.Append(strLine);
}
sr.Close();
这段代码很好用。我用WebRequest.Create(“http://www.google.com”)替换了WebRequest.Create(“url”)方法的在线URI。如果您通过了正确的网址,请检查该部分。