Get Error number in WebException Error

前端 未结 4 1800
再見小時候
再見小時候 2021-02-19 04:40

How To Get Error number in WebException Error?

try
{
     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(\"site\");
     HttpWebResponse response         


        
4条回答
  •  执念已碎
    2021-02-19 05:14

    You'll want to run a test to make sure that it was a ProtocolError:

    if (e.Status == WebExceptionStatus.ProtocolError) 
    {
        Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
        Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
    }
    

提交回复
热议问题