By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Handling the System.Net.WebException ....

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

try
{
responseArray =
myWebClient.UploadValues(uriString,"POST",myNameVa lueCollection);
}
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 !
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"genc_ ymeri at hotmail dot com" <ge********@hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP09.phx.gbl...
Hi,
I'm trying to recieve the response status code rather than the message in
the below code :

try
{
responseArray =
myWebClient.UploadValues(uriString,"POST",myNameVa lueCollection);
}
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 !

Nov 16 '05 #2

P: n/a
>such as HttpWebResponse or FileWebResponse) which provides further
properties & details on the problem >>>>
This is what I was looking for,,,,

Thanks a lot.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eq**************@tk2msftngp13.phx.gbl... 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

"genc_ ymeri at hotmail dot com" <ge********@hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP09.phx.gbl...
Hi,
I'm trying to recieve the response status code rather than the message in
the below code :

try
{
responseArray =
myWebClient.UploadValues(uriString,"POST",myNameVa lueCollection);
}
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 !


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.