How to get status code from webclient?

前端 未结 10 1894
轮回少年
轮回少年 2020-11-29 04:03

I am using the WebClient class to post some data to a web form. I would like to get the response status code of the form submission. So far I\'ve found out how

10条回答
  •  暖寄归人
    2020-11-29 05:05

    You should use

    if (e.Status == WebExceptionStatus.ProtocolError)
    {
       HttpWebResponse response = (HttpWebResponse)ex.Response;             
       if (response.StatusCode == HttpStatusCode.NotFound)
          System.Diagnostics.Debug.WriteLine("Not found!");
    }
    

提交回复
热议问题