473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Getting response when web file does not exist.

I am trying to use an HttpWebRequest object to get resource from a website.
Now, some of the files that I try to get may not exist. I would like to
check for that condition. When I call GetResponse on files that do not
exist, I get an exception. What I would like is not to have the exception
but allow me to check that StatusCode property for the 402 condition. How
can I do this?
Nov 15 '05 #1
2 1678
try
{
....
HttpWebRequest ...
....
}
catch{}

"Peter Rilling" <pe***@nospam.rilling.net> schrieb im Newsbeitrag
news:OQ**************@TK2MSFTNGP09.phx.gbl...
I am trying to use an HttpWebRequest object to get resource from a website. Now, some of the files that I try to get may not exist. I would like to
check for that condition. When I call GetResponse on files that do not
exist, I get an exception. What I would like is not to have the exception
but allow me to check that StatusCode property for the 402 condition. How
can I do this?

Nov 15 '05 #2
Peter Rilling wrote:
I am trying to use an HttpWebRequest object to get resource from a
website. Now, some of the files that I try to get may not exist. I
would like to check for that condition. When I call GetResponse on
files that do not exist, I get an exception. What I would like is
not to have the exception but allow me to check that StatusCode
property for the 402 condition. How can I do this?


Peter,

HTTP protocol errors such as 404 are escalated by the framework as
WebException instances with the Status property set to
WebExceptionStatus.ProtocolError. In that case, the WebException will have a
valid WebResponse instance in its Response property:

try {
// Do WebRequest
}
catch (WebException ex) {
if (ex.Status == WebExceptionStatus.ProtocolError) {
HttpWebResponse response = ex.Response as HttpWebResponse;
if (response != null) {
// Process response, look for HTTP status code, etc.
}
}
}

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
4
by: Max Dupenois | last post by:
I've seen numerous articles with similair (similar sp?) titles to this in my search.. unfortunately none of them seem to contain what i want, (or if they do i need someone to point out my stupidity...
2
by: David Hearn | last post by:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during the execution of the current...
16
by: lawrence k | last post by:
I've a file upload script on my site. I just now used it to upload a small text document (10k). Everything worked fine. Then I tried to upload a 5.3 meg Quicktime video. Didn't work. I've...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
7
by: AC [MVP MCMS] | last post by:
I've got an page used for downloads that acts similarily to the MSFT downloads.... page displays and refreshes itself which causes a XML file to be streamed to the client. The streaming of the...
4
by: Hexman | last post by:
Code below ---- I've asked a similar question on this forum earlier. This is a slightly different situation. Previous Question ---- I'm trying to save some specific web pages to disk as...
1
by: vijaykumars | last post by:
+-----------------------------------------------------------------------------+ Summaries: +-----------------------------------------------------------------------------+ Installation...
1
imrosie
by: imrosie | last post by:
Please help with this one,,,,,I've been trying everything in my arsenal to fix this one. I'm stumped.... I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.