How to get status code from webclient?

前端 未结 10 1913
轮回少年
轮回少年 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 04:44

    Tried it out. ResponseHeaders do not include status code.

    If I'm not mistaken, WebClient is capable of abstracting away multiple distinct requests in a single method call (e.g. correctly handling 100 Continue responses, redirects, and the like). I suspect that without using HttpWebRequest and HttpWebResponse, a distinct status code may not be available.

    It occurs to me that, if you are not interested in intermediate status codes, you can safely assume the final status code is in the 2xx (successful) range, otherwise, the call would not be successful.

    The status code unfortunately isn't present in the ResponseHeaders dictionary.

提交回复
热议问题