0

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)
{
}
Fabio Milheiro
  • 8,100
  • 17
  • 57
  • 96

1 Answers1

2

Catch WebException and access e.Response property.

maciejkow
  • 6,403
  • 1
  • 27
  • 26
  • 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 Jun 03 '10 at 13:16