views:

738

answers:

3

Hi

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

+1  A: 

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
        }
    }
}
Mitch Wheat
+1  A: 

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?

Christian Nunciato
A: 

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

CruelIO