title: Get XML body of a 400 or 500 HTTP XML response
body: <p>Long story short, I am sending an XML HTTP post request to an application server, and I am getting back a response, also in the form of XML HTTP. </p>
  
  <p>I have a test site available to me which allows me to see what the server's actual response is, visually, in the form of XML, but I cannot access this XML from my C# code the way it is.</p>
  
  <p>The XML coming back from the application server in my test case looks like this:</p>
  
  <pre><code>&lt;Error&gt;&lt;Message&gt;StringErrorMessage&lt;/Message&gt;&lt;/Error&gt;
  </code></pre>
  
  <p>However, I have had no luck accessing this basic XML to retrieve the value of "StringErrorMessage" for the creation of a detailed error report.</p>
  
  <pre><code>... More code above, all wrapped in a try{}...
  
  _response = Serializer.DeserializeObject&lt;T&gt;(ObjectRequest.GetResponse().GetResponseStream());
  
          }
          catch (System.Net.WebException exceptionParameter)
          {
              var response = (HttpWebResponse)exceptionParameter.Response;
              string webExceptionStatus = exceptionParameter.Message;
              _exception = exceptionParameter;
              return false;
          }
  </code></pre>
  
  <p>I have consulted 
  <a href="https://stackoverflow.com/questions/5409138/c-sharp-getting-the-response-body-from-a-403-error">C# - Getting the response body from a 403 error</a></p>
  
  <p>and</p>
  
  <p><a href="https://stackoverflow.com/questions/7735893/get-response-body-on-400-http-response-in-android">Get response body on 400 HTTP response in Android?</a></p>
  
  <p>The first link's solution doesn't seem to give me access to the basic XML as part of any response object's properties. I am almost positive that there must be a byte[] in there somewhere (in the response, or in the exception object) that can be converted into a char[], which can be converted to a string, which can be converted to my XML body, but I have not been able to find it. The second link's solution is not exactly viable for me because I have to get the response body back in the form of XML, as it might not be an error, but an object that must be deserialized. This particular side of things, I cannot change.</p>
  
  <p>Any advice would be very much appreciated. 
   - Eli</p>
  
  <p>EDIT: Just wanted to clarify that my basic code is working okay for non-error situations, and is deserializing the XML just fine. It's when my code encounters a HTTP 400 or an HTTP 500 error, where accessing the XML from the catch statement becomes a problem, because my code immediately throws an exception.</p>