Handling the System.Net.WebException ....

  • Thread starter Thread starter genc_ ymeri at hotmail dot com
  • Start date Start date
G

genc_ ymeri at hotmail dot com

Hi,
I'm trying to recieve the response status code rather than the message in
the below code :

try
{
responseArray =
myWebClient.UploadValues(uriString,"POST",myNameValueCollection);
}
catch (System.Net.WebException ex)
{
// I'm excpecting 401 error (SC_UNAUTHORIZED) or similiar errors
// I want to recieve the error code rather then :
// "The remote server returned an error: (401) Unauthorized."

}

Any tip very much appreciated !
 
genc_ ymeri,
Did you look at the properties of WebException?

Such as WebException.Status?

Also WebException has a Response property that will return the WebResponse
object from the actual request/response. WebException.Response can be cast
to the specific type of request being made (such as HttpWebResponse or
FileWebResponse) which provides further properties & details on the problem,
such as HttpWebResponse.StatusCode & HttpWebResponse.StatusDescription.

Hope this helps
Jay
 
such as HttpWebResponse or FileWebResponse) which provides further
properties & details on the problem >>>>

This is what I was looking for,,,,

Thanks a lot.
 
Back
Top