This is similar to a question asked here: httpWebRequest - get error content but I'm hoping to provide some more information in hope of an answer.
I am integrating with the LinkedIn API using C#. When I make an invalid call to the API, it can return a HTTP response like such (from Fiddler):
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
x-li-request-id: VL2EER2ROJ
Date: Tue, 16 Oct 2012 08:52:59 GMT
Vary: *
x-li-format: xml
Content-Type: text/xml;charset=UTF-8
Content-Length: 266
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>404</status>
<timestamp>1350377580000</timestamp>
<request-id>VL2EER2ROJ</request-id>
<error-code>0</error-code>
<message>Could not find member {/people/XXXXXX}</message>
</error>
I would specifically like to get at the error xml, however HttpWebRequest seems to simply throw the exception and then has nothing to do with the content. In my debugger, I can see that the content length is 266, but any attempt to call (System.Net.WebException).Response.GetResponseStream()
results in a stream was not readable
exception.
This method of returning error messages within a non 200 HTTP status response seems quite popular in web APIs - I'm hoping there is a way to get at these responses...