views:

85

answers:

1

The httpRequest.GetResponse() method gets a status code of 422 (Unprocessable entity) and throws an exception. In this webservice I am using, I know that an XML response is also sent and I need to get that response in order to find out why the server could not process my request.

How do I get the XML response in the catch block?

try
{
    // Submits the HTTP request to create the invoice and gets the XML response.
    using (HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse)
    {
        // my code...
        return httpResponse;
    }
}
catch (Exception e)
{
}
+2  A: 

Catch WebException and access e.Response property.

maciejkow
Thank you maciejkow! Here, another related question on stackoverflow that might also be useful to other users trying to get the response from the exception http://stackoverflow.com/questions/1167913/webexception-when-reading-a-webexceptions-response-stream
Fabio Milheiro