简体   繁体   中英

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. 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?

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

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
        }
    }
}

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. 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.

As for your particular error, it's hard to say; 403 can indicate a few different things. 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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM