winsock error with HttpWebResponse

  • Thread starter Wilfried Mestdagh [MapPoint MVP]
  • Start date
W

Wilfried Mestdagh [MapPoint MVP]

Hello,

I connect to a server like this:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
req.Method = "POST";
StreamWriter stOut = new StreamWriter(req.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(xml);
stOut.Close();
HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();

When the server answers with a 502 then I have an exception in the last
line. the message is: The remote server returned an error: (502) Bad Gateway.

But where can I find the 502 itself? It should be stored in some property
but I cannot find it. I need to know the return value from the server and
react in my code depending on particular return values.
 
W

Wilfried Mestdagh [MapPoint MVP]

Hi,

I found it:

} catch (WebException ex) {
HttpWebResponse httpWebResponse = ex.Response as HttpWebResponse;
if (httpWebResponse != null)
Console.WriteLine((int)httpWebResponse.StatusCode);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top