代码如下:
string strUrl = "http://localhost/test.asp";
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(strUrl);
HttpWReq.Method = "GET";
string strHtml = "";
try
{
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse(); Stream stm = HttpWResp.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
StreamReader readStream = new StreamReader(stm, encode);
strHtml = readStream.ReadToEnd();
HttpWResp.Close();
}
catch(Exception err)
{
strHtml = err.Message;
}
Label1.Text = strHtml;我现在只能获得“ 远程服务器返回错误: (500) 内部服务器错误。 ”这样的信息。
我想获得全部的具体错误信息。

解决方案 »

  1.   

    To:koenemy我得到的如下:
    System.Net.WebException: 远程服务器返回错误: (500) 内部服务器错误。 at System.Net.HttpWebRequest.CheckFinalStatus() at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.HttpWebRequest.GetResponse() at WebApplication3.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs:line 35所以还是不行阿。
      

  2.   

    Response.StatusCode
    获取状态码,20为成功,504为文件未找到。自己查查吧,呵。