Question

I'm having some problem's grabbing a response stream from a request that returning status code 422.

HttpWebResponse objResponse = (HttpWebResponse)wr.GetResponse();

The wr.GetResponse throws an webexception because the status code isnt 201.
So i can never get the response stream from the remote server. But it does return important information in the ResponseStream.

So my question is how to retrieve the ResponseStream on a request that doesnt return 201 but still returns data.

Was it helpful?

Solution

The WebException that is thrown contains a reference to the response from which you can get the response steam.

catch(WebException ex)
{
     ex.Response.GetResponseStream();
}

OTHER TIPS

Use TcpClient and send the HTTP Request manually. It's a pretty simple request format.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top