473,395 Members | 2,436 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,395 software developers and data experts.

Catching web exception

Hello.

If I just want to check whether a specific URL returns error (404, 403,
500...) or not, I do this:

HttpWebResponse oResponse = null;
try
{
oResponse = (HttpWebResponse)oRequest.GetResponse();
}
catch (WebException oException)
{

But examining the net traffic I have found out that, if the URL doesn't
return an error and corresponds to a big file (4 MB for instance), the
program is retreiving around 1 MB of data. I don't want my program to
generate this traffic, I only want to check if the URL is ok, so how can
I improve this?

Thanks in advance.

Andrew [ knocte ]

--
Mar 7 '06 #1
3 2033
try:

oRequest.Method = "HEAD";

this will make sure the server does not send you the content of the page.

hth,
Baileys

Andrés G. Aragoneses wrote:
Hello.

If I just want to check whether a specific URL returns error (404, 403,
500...) or not, I do this:

HttpWebResponse oResponse = null;
try
{
oResponse = (HttpWebResponse)oRequest.GetResponse();
}
catch (WebException oException)
{

But examining the net traffic I have found out that, if the URL doesn't
return an error and corresponds to a big file (4 MB for instance), the
program is retreiving around 1 MB of data. I don't want my program to
generate this traffic, I only want to check if the URL is ok, so how can
I improve this?

Thanks in advance.

Andrew [ knocte ]

Mar 8 '06 #2
Thus wrote Baileys,
try:

oRequest.Method = "HEAD";

this will make sure the server does not send you the content of the
page.


HEAD will do trick if the original requests are all GETs. If they are POSTs,
HEAD likely won't work, as HEAD is technically just a special GET.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 8 '06 #3
Joerg Jooss escribió:
Thus wrote Baileys,
try:

oRequest.Method = "HEAD";

this will make sure the server does not send you the content of the
page.


HEAD will do trick if the original requests are all GETs. If they are
POSTs, HEAD likely won't work, as HEAD is technically just a special GET.

Cheers,


Thanks very much to both of you. Currently my needs fit well with only
GET :)

Regards,

Andrew [ knocte ]

--
Mar 10 '06 #4

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

Similar topics

6
by: EAS | last post by:
Hi, I'm wondering if there is any way to keep a program running when it runs into an error (using the 'try' structure) and print the traceback to the screen? Thanks.
8
by: Adam H. Peterson | last post by:
Hello, I sometimes find myself writing code something like this: try { Derived &d=dynamic_cast<Derived&>(b); d.do_something_complicated(); // etc.... } catch (std::bad_cast) { throw...
2
by: Adam | last post by:
If I catch an exception in a static callback method like: private static void ResponseCallback(IAsnycResult asyncResult) { try { //code...code...code } catch (WebException e) { //handle...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
2
by: Geoff O | last post by:
I have a try catch block in a web service that executes ADO.NET code that interfaces with an Oracle database. In addition, I have a try catch block in the client around the call to the web...
2
by: Paolo | last post by:
Hello Everybody! Considering this code: try { ExecuteOperation(); } catch {
2
by: fischermx | last post by:
Exception Catching difference between VC++ and C# In C# I have this: try { int x, y, z; x = 20; y = 0;
5
by: Amit Gupta | last post by:
Py'ites I am using pdb to check my code, and I would like to put a statement like equivalent of "C++gdb>catch throw". Basically, I would like debugger to start as soon as an exception is...
3
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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,...

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.