1

我正在使用这个代码,这给了我问题

       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
4

1 回答 1

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。如果您传递正确的网址,请检查该部分。

于 2013-06-12T07:12:52.027 回答