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 to get the status code if there is a exception
Catch wex As WebException
If TypeOf wex.Response Is HttpWebResponse Then
msgbox(DirectCast(wex.Response, HttpWebResponse).StatusCode)
End If
However if the form is submitted successfully and no exception is thrown then I won’t know the status code(200,301,302,…)
Is there some way to get the status code when there is no exceptions thrown?
PS: I prefer not to use httpwebrequest/httpwebresponse
Tried it out. ResponseHeaders do not include status code.
If I’m not mistaken,
WebClientis 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 usingHttpWebRequestandHttpWebResponse, 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
ResponseHeadersdictionary.