简体   繁体   English

我如何从HttpWebResponse获取详细信息

[英]How do i get detailed info from a HttpWebResponse

I'm making a post httpwebrequst, but in the HttpWebResponse im getting an error code 403 forbidden. 我正在发布httpwebrequst,但在HttpWebResponse中,我收到了禁止输入的错误代码403。 Now that error isnt very use full to me. 现在,该错误对我来说已不是很有用。

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更多“服务器端”的细节来自失败的httpwebrequest,只是错误代码?

thank you 谢谢


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 我得到403很好,我只是想知道为什么当我在webexception中看到类似的内容时,测试程序为什么可以告诉SSL需要SSL

If a WebException is thrown because of a protocol error, its Response property will contain the actual response received from the web server. 如果由于协议错误而引发WebException,则其Response属性将包含从Web服务器收到的实际响应。

try 
{
    // Do WebRequest
}
catch (WebException ex) 
{
    if (ex.Status == WebExceptionStatus.ProtocolError) 
    {
        HttpWebResponse response = ex.Response as HttpWebResponse;
        if (response != null)
        {
            // Process response
        }
    }
}

There's not an explicit way to ask for more detailed information, no -- basically, ya get what ya get. 没有明确的方法要求更详细的信息,不,基本上,您会得到什么。

That said, Web servers often return documents along with those error codes that sometimes contain useful information, much like the one you got explaining the problem with the SSL cert. 也就是说,Web服务器通常会返回文档以及有时包含有用信息的那些错误代码,就像您解释SSL证书问题的代码一样。 For help sniffing out problems like this, check out Fiddler -- it'll show you just about everything there is to know about your server responses. 为了帮助您发现此类问题,请查看Fiddler ,它会向您显示有关服务器响应的所有信息。

As for your particular error, it's hard to say; 至于您的特定错误,很难说。 403 can indicate a few different things. 403可以指示一些不同的事物。 But if you got back a response indicating something having to do with SSL, you may just be dealing with a bad or expired certificate ( see this question ), or the server may be requiring a secure connection but not getting one. 但是,如果您返回了表明与SSL有关的响应,则可能只是在处理错误或已过期的证书( 请参阅此问题 ),或者服务器可能需要安全连接但没有安全连接。 Have you tried just hitting the URL directly with a Web browser, just to see whether you get prompted with a warning indicating a certificate problem, or anything other than an unmediated 403 response? 您是否尝试过使用Web浏览器直接点击URL,只是为了查看您是否收到警告,提示是否存在证书问题或未经处理的403响应以外的其他提示?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得“200 OK”的HttpWebResponse? - How do I get an HttpWebResponse for “200 OK”? 如何从HttpWebResponse创建ODataMessageReader? - How do I create an ODataMessageReader from an HttpWebResponse? 在哪里可以找到有关该用户实体的详细信息,以及如何获取该实例的实例? - where do I find detailed info on the user entity and how do I get an instance of it? 如何获取Bot Connector服务对从注册通道发送到我的终端的消息所做的详细信息? - How can I get detailed info on what Bot Connector Service does to messages sent from registered channels to my endpoint? 如何从 HttpWebResponse 中获取 substring 信息? - How do I substring information out of an HttpWebResponse? 如何提高HttpWebResponse的性能? - How do I increase the performance of HttpWebResponse? 如何解码编码的 HttpWebResponse? - How do I decode an encoded HttpWebResponse? 如何从HttpWebResponse获取字符串uri - How to get string uri from HttpWebResponse C# 与 PowerShell。 如何获取详细的异常信息? - C# vs PowerShell. How to get detailed exception info? 如何将Cookie从System.Net.HttpWebResponse携带到下一个System.Net.HttpWebRequest? - How do I carry a cookie from a System.Net.HttpWebResponse to the next System.Net.HttpWebRequest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM