473,383 Members | 1,879 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,383 software developers and data experts.

HttpWebRequest timeouts

Hi

I'm trying to building something to check the availability of a web page.

The code is using a HttpWebRequest, bypassing our proxy server and hitting
both HTTP/HTTPS pages. Initially I get a HTTP response code of 200. After
the second or third attempt at hitting the same page over a period of a
couple of minutes, I get a timeout. Note that I'm creating a fresh
HttpWebRequest each time I hit the web page.

I restart the console app and it works, but again, only for a couple of
attempts.

Any ideas?

Thanks

Glenn

Code below...
public override bool RunTest()

{

bool success = false;

HttpWebRequest request = WebRequest.Create( WebSiteProperties.WebSiteUrl )
as HttpWebRequest;

request.CachePolicy = new HttpRequestCachePolicy(
HttpRequestCacheLevel.BypassCache );

try

{

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

HttpStatusCode responseHttpStatusCode = response.StatusCode;

List<stringexpectedHttpStatusCodes = new List<string>(

WebSiteProperties.ExpectedHttpStatusCodes.Split( ",".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries ) );

success = expectedHttpStatusCodes.Contains( (
(int)responseHttpStatusCode ).ToString() );

return success;

}

catch ( Exception exception )

{

return success;

}

}
Mar 5 '07 #1
5 3487
On 5 Mar, 15:18, "Glenn" <glenn.csh...@yahoo.co.ukwrote:
Hi

I'm trying to building something to check the availability of a web page.

The code is using a HttpWebRequest, bypassing our proxy server and hitting
both HTTP/HTTPS pages. Initially I get a HTTP response code of 200. After
the second or third attempt at hitting the same page over a period of a
couple of minutes, I get a timeout. Note that I'm creating a fresh
HttpWebRequest each time I hit the web page.

I restart the console app and it works, but again, only for a couple of
attempts.

Any ideas?

Thanks

Glenn

Code below...
public override bool RunTest()

{

bool success = false;

HttpWebRequest request = WebRequest.Create( WebSiteProperties.WebSiteUrl )
as HttpWebRequest;

request.CachePolicy = new HttpRequestCachePolicy(
HttpRequestCacheLevel.BypassCache );

try

{

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

HttpStatusCode responseHttpStatusCode = response.StatusCode;

List<stringexpectedHttpStatusCodes = new List<string>(

WebSiteProperties.ExpectedHttpStatusCodes.Split( ",".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries ) );

success = expectedHttpStatusCodes.Contains( (
(int)responseHttpStatusCode ).ToString() );

return success;

}

catch ( Exception exception )

{

return success;

}
}- Hide quoted text -

- Show quoted text -
I haven't got the code to hand but I've had something like this in the
past.
I think it comes down to not closing/disposing the HttpWebResponse
object.

Mar 5 '07 #2
Problem solved.

I should have closed the damn response stream, damn, damn, damn, damn it!

Glenn

"Glenn" <gl**********@yahoo.co.ukwrote in message
news:OA**************@TK2MSFTNGP05.phx.gbl...
Hi

I'm trying to building something to check the availability of a web page.

The code is using a HttpWebRequest, bypassing our proxy server and hitting
both HTTP/HTTPS pages. Initially I get a HTTP response code of 200.
After the second or third attempt at hitting the same page over a period
of a couple of minutes, I get a timeout. Note that I'm creating a fresh
HttpWebRequest each time I hit the web page.

I restart the console app and it works, but again, only for a couple of
attempts.

Any ideas?

Thanks

Glenn

Code below...
public override bool RunTest()

{

bool success = false;

HttpWebRequest request = WebRequest.Create( WebSiteProperties.WebSiteUrl )
as HttpWebRequest;

request.CachePolicy = new HttpRequestCachePolicy(
HttpRequestCacheLevel.BypassCache );

try

{

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

HttpStatusCode responseHttpStatusCode = response.StatusCode;

List<stringexpectedHttpStatusCodes = new List<string>(

WebSiteProperties.ExpectedHttpStatusCodes.Split( ",".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries ) );

success = expectedHttpStatusCodes.Contains( (
(int)responseHttpStatusCode ).ToString() );

return success;

}

catch ( Exception exception )

{

return success;

}

}


Mar 5 '07 #3
Thanks Matt

Yep, you're right, although HttpWebRequest and it's response counterpart
don't implement IDisposable, you have to remember to close the streams, and
definately don't cross them ;-).

Time for the pub I think.

Glenn

"Matt Lacey" <m.*****@fdsltd.co.ukwrote in message
news:11**********************@n33g2000cwc.googlegr oups.com...
On 5 Mar, 15:18, "Glenn" <glenn.csh...@yahoo.co.ukwrote:
>Hi

I'm trying to building something to check the availability of a web page.

The code is using a HttpWebRequest, bypassing our proxy server and
hitting
both HTTP/HTTPS pages. Initially I get a HTTP response code of 200.
After
the second or third attempt at hitting the same page over a period of a
couple of minutes, I get a timeout. Note that I'm creating a fresh
HttpWebRequest each time I hit the web page.

I restart the console app and it works, but again, only for a couple of
attempts.

Any ideas?

Thanks

Glenn

Code below...
public override bool RunTest()

{

bool success = false;

HttpWebRequest request = WebRequest.Create(
WebSiteProperties.WebSiteUrl )
as HttpWebRequest;

request.CachePolicy = new HttpRequestCachePolicy(
HttpRequestCacheLevel.BypassCache );

try

{

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

HttpStatusCode responseHttpStatusCode = response.StatusCode;

List<stringexpectedHttpStatusCodes = new List<string>(

WebSiteProperties.ExpectedHttpStatusCodes.Split ( ",".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries ) );

success = expectedHttpStatusCodes.Contains( (
(int)responseHttpStatusCode ).ToString() );

return success;

}

catch ( Exception exception )

{

return success;

}
}- Hide quoted text -

- Show quoted text -

I haven't got the code to hand but I've had something like this in the
past.
I think it comes down to not closing/disposing the HttpWebResponse
object.

Mar 5 '07 #4
Glenn <gl**********@yahoo.co.ukwrote:
Yep, you're right, although HttpWebRequest and it's response counterpart
don't implement IDisposable, you have to remember to close the streams, and
definately don't cross them ;-).
WebResponse implements IDisposable, but WebRequest doesn't.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 5 '07 #5
Ah, didn't notice that.

Thanks

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
Glenn <gl**********@yahoo.co.ukwrote:
>Yep, you're right, although HttpWebRequest and it's response counterpart
don't implement IDisposable, you have to remember to close the streams,
and
definately don't cross them ;-).

WebResponse implements IDisposable, but WebRequest doesn't.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Mar 6 '07 #6

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

Similar topics

4
by: Mark Fletcher | last post by:
Hi, Im in the process of writing a program that crawls a website. Im using the HttpWebRequest and HttpWebResponse classed to get content. To make my application more scalable, my application is...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
2
by: mircu | last post by:
Hi, I need a quick solution to make my application behave correctly when one of these timeouts occurs. I have some logic in session_start but when the authentication cookie timeouts the user is...
11
by: Keith Patrick | last post by:
Could someone explain to me the relationship between these two classes? I am ripping my hair out trying to divert an HttpRequest to a new location via an HttpWebRequest, but I cannot get my...
0
by: Alex Papadimoulis | last post by:
Hey Group, I'm in the process of converting an ASP-based site to an ASP.NET site and built a control that wraps around an ASP page. The control simply does a GET to the same server to render the...
0
by: Alex Papadimoulis | last post by:
Hey Group, I'm in the process of converting an ASP-based site to an ASP.NET site and built a control that wraps around an ASP page. The control simply does a GET to the same server to render the...
1
by: Eric Cadwell | last post by:
Are there two distinct timeouts on HttpWebRequest.GetResponse()? If I recall correctly, I've seen an "operation timed out" that was not the same as request time out. Thanks, Eric
0
by: joshblair | last post by:
Hello, I am trying to post XML documents to a third party using the HttpWebRequest. This URL uses HTTPS (SSL) but I don't have a client certificate to deal with. Apparently they are using...
10
by: Zytan | last post by:
I have a TcpClient. I set the read/write timeouts at 1 minute (in milliseconds). I get a NetworkStream from it and confirm the timeouts still exist. I do a NetworkStream.Write() and then a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.