views:

28

answers:

1

I have a web app which talks to a custom back-end server over HTTP. The server provides its responses in XML and I use Linq-to-XML to parse the results. If the server cannot process a query it will send back a 400 bad request header which includes detailed information about the problem. i.e.

    HTTP/1.1 400 Bad Request (invalid query)

On the client side I use XDocument.Load(uri) to retrieve and parse the response. When a bad request happens, it throws a WebException. The problem is the Message property is set to "Bad Request". I don't know if it truncated the response string or if it just parsed the 400 code and generated the message on its own. Is there a way to get the original response string?

A: 

You can extract the raw response from a WebException. We do this in RestSharp because non-200 status codes are not exactly exceptional in real-world usage. You can see an example here.

John Sheehan
That worked great. Thank You.
Ferruccio