开发者

Is there a way to get the original HTTP response string from a WebException?

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 reque开发者_如何学JAVAst 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜