开发者

How do I get the XML response after I receive an HTTP status different than OK?

开发者 https://www.devze.com 2023-01-01 21:31 出处:网络
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

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)
{
}


Catch WebException and access e.Response property.

0

精彩评论

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