如何从Web客户端的状态code? [英] How to get status code from webclient?
问题描述
我现在用的是 Web客户端
类张贴一些数据到Web表单。我想获得表单提交的响应状态code。到目前为止,我已经找到了如何让状态code,如果有一个例外
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
但是,如果表单提交成功,并没有异常被抛出,然后我就不知道了状态code(200301302 ...)
However if the form is submitted successfully and no exception is thrown then I won't know the status code(200,301,302,...)
有没有办法让状态code时,有没有异常抛出?
Is there some way to get the status code when there is no exceptions thrown?
PS:我preFER不使用的HttpWebRequest / httpwebresponse
PS: I prefer not to use httpwebrequest/httpwebresponse
推荐答案
尝试过了。 responseHeaders响应不包括状态code。
Tried it out. ResponseHeaders do not include status code.
如果我没有记错, Web客户端
能抽象出多个不同的请求,在一个单一的方法调用(如正确处理100继续响应,重定向等)。我怀疑,如果没有使用的HttpWebRequest
和 HttpWebResponse
,明显的状态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.
它发生,我认为,如果你不感兴趣的中间状态codeS,你可以放心地假设最终状态code是在2XX(成功)范围内,否则,调用将不会成功
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.
状态code不幸的是,不是present在 responseHeaders响应
字典。
The status code unfortunately isn't present in the ResponseHeaders
dictionary.
这篇关于如何从Web客户端的状态code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!