views:

94

answers:

2

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.

+1  A: 

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

Jan Bannister
Guess that could be a solution. But isnt there a way to use HttpWebResponse/HttpWebRequest
Patrik Potocki
I guess you could test the StatusCode and then look in the Headers collection to see what header info the server returned you
Jan Bannister
Well yes guess thats possible. But the thing is that it returns data in the ResponseBody (ResponseStream). So i cant reach that data when looking at the headers
Patrik Potocki
+2  A: 

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();
}
Peter