我如何从一个详细信息,HttpWebResponse [英] How do i get detailed info from a HttpWebResponse
问题描述
我在做一个帖子httpwebrequst,但在HttpWebResponse即时得到禁止错误代码403。现在,错误很心不是使用完整的我。
I'm making a post httpwebrequst, but in the HttpWebResponse im getting an error code 403 forbidden. Now that error isnt very use full to me.
然后我尝试了testprogram(即我没有源代码:(),并用它来进行相同的后,它返回了禁止代码403,但也告诉我,需要全髋关节置换SSL。所以,才有可能获得更多的服务器端细节出了一个失败的HttpWebRequest,只是在错误码?
I then tried a testprogram (that i do not have the source code to :() and used it to make the same post, and it returned with a code 403 forbidden but also told me tha SSL was needed. So is it possible to get more "serverside"details out of a failed httpwebrequest that just the errorcode?
感谢您
只是为了明确的事情了,它的罚款即时得到403,我只是想知道为什么测试程序可以告诉大家,SSL是需要的SSL时,我可以在引发WebException看到这样的事情
Just to clear things up. Its fine that im getting the 403, i was just wondering why the test program could tell that SSL that SSL was needed when i can see anything like that in the webexception
推荐答案
如果一个引发WebException,是因为协议错误的抛出,其响应
属性将包含实际响应来自网络
服务器接收。
If a WebException is thrown because of a protocol error, its Response property will contain the actual response received from the web server.
try
{
// Do WebRequest
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse response = ex.Response as HttpWebResponse;
if (response != null)
{
// Process response
}
}
}
这篇关于我如何从一个详细信息,HttpWebResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!