远程服务器返回错误:(503)服务器不可用Asp.Net

时间:2013-06-12 06:38:27

标签: asp.net web-crawler

我正在使用此代码给我发出问题

       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

1 个答案:

答案 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。如果您通过了正确的网址,请检查该部分。