473,769 Members | 4,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling the System.Net.WebE xception ....

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

try
{
responseArray =
myWebClient.Upl oadValues(uriSt ring,"POST",myN ameValueCollect ion);
}
catch (System.Net.Web Exception ex)
{
// I'm excpecting 401 error (SC_UNAUTHORIZE D) 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
2 16123
genc_ ymeri,
Did you look at the properties of WebException?

Such as WebException.St atus?

Also WebException has a Response property that will return the WebResponse
object from the actual request/response. WebException.Re sponse 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 .StatusDescript ion.

Hope this helps
Jay

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

try
{
responseArray =
myWebClient.Upl oadValues(uriSt ring,"POST",myN ameValueCollect ion);
}
catch (System.Net.Web Exception ex)
{
// I'm excpecting 401 error (SC_UNAUTHORIZE D) 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
>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******** ******@tk2msftn gp13.phx.gbl... genc_ ymeri,
Did you look at the properties of WebException?

Such as WebException.St atus?

Also WebException has a Response property that will return the
WebResponse object from the actual request/response. WebException.Re sponse
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 .StatusDescript ion.

Hope this helps
Jay

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

try
{
responseArray =
myWebClient.Upl oadValues(uriSt ring,"POST",myN ameValueCollect ion);
}
catch (System.Net.Web Exception ex)
{
// I'm excpecting 401 error (SC_UNAUTHORIZE D) 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3312
by: Joe Bloggs | last post by:
I have a C# MRS application that uses the ReportingService's Render method to retrieve a byte array containing a report. The following error message occurs An unhandled exception of type 'System.Net.WebException' occurred in system.web.services.dll Additional information: The operation has timed-out.
1
2260
by: etantonio | last post by:
Good morning, I've a problem, in the past I translate my site from google or altavista with a code similar to this : <%@ Page Language="c#" Trace="true" Debug="true" %> <%@ import Namespace="System.Net" %> <%@ import Namespace="System.IO" %> <script runat="server"> void Page_Load(Object Src, EventArgs E ) { if (!Page.IsPostBack)
3
2059
by: Mr Newbie | last post by:
I'm testing error handling configurations and having some trouble. I created a WebForm called. ErrDefault.aspx and I am trying to use the Page error attribute to force the redirection to a custom page, but I only get and unhandled exception page and it does not direct me to my specific page. I'm probably doing something really stupid, but I cant see what . Any Ideas ? - Thanx Mr N --------- DETAILS BELOW -----------
3
3027
by: bag | last post by:
Greetings! I am currently creating a program that will retrieve information from a web site based on user input. I have the system working correctly, but am running into a problem (that I probably should have checked for in the beginning ;) Summary: Using an HTTPRequest, I want to be able to retrieve the page a server would send with an error (like a custom 404) instead of getting a WebException.
1
3778
by: Albert Ludwig | last post by:
Hallo NewsGroup, in meiner Anwendung rufe ich ein Internet-asp-script auf. Diese Funktionalität habe ich in der Funktion "fuwHandelWebRequestPost" (siehe unten) gekapselt. Diese Funktion arbeitet ausgezeichnet. Leider bereitet diese Routine Probleme (WebException), wenn innerhalb 30 sec. sie ein weiteres Mal aufgerufen wird. Vermutlich blockiert der 1. Aufruf noch die Ressource und diese muss explizit "geschlossen" werden.
2
25463
by: tlan | last post by:
Hi, I got this error when I move my web service to Windows2003 server. I spent hours scouting on the internet and could find any answer. Please help!!! I the webservice is timeout between 1 -2 minutes when my web app, which consume this webService, retrieves a large amount of data. When I perform the same operation to retrieve smaller amount of data, it works fine. The timeout value I set for my web app, web service, and sql
1
3511
by: Tim Reynolds | last post by:
Team, From a windows service, we consume a web service on another server and occasionally receive System.Net.WebException: The underlying connection was closed:. For some clients we call, we do not see this as we ran into this previoulsy, made a posting, and received some suggested code to resolved. The code was put in their proxy classes and was this... protected override WebRequest GetWebRequest(Uri uri) {HttpWebRequest webRequest =...
8
14103
by: Tim Reynolds | last post by:
Our .Net application calls a web method of aplpication 2 that resides on their Apache server. When I as a developer C#, Studios 2003, make the call to their web method from my desktop, I receive no exceptions - completes fine. Their web service url was added as a web reference to our project with no problem. The following was generated as part of the proxy class: /// <remarks/> public DueDateAvailabilityResponse...
6
2101
by: RonL | last post by:
What is the recommended best technique for handling errors/exceptions in ASP.Net. I've read about the following techniques: 1. Try/Catch 2. Page_Error 3. Application_Error in the glabal.asax 4. Custom errors in Web.Config.
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.