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

HttpWebRequest.GetResponse() throwing Timeout

I'm trying to create a simple screen scraping application and I kept
getting a System.Net.WebException thrown back with a message of "The
operation has timed-out." At first I thought it was some kind of
connectivity issue on the machine. It didn't make sense though, because I
can open up a browser on the same machine and easily browse
the web.

I'm stumped. I looked over my code for any errors and just couldn't find
what I was doing wrong. So, I went out and
found a code sample from www.gotdotnet.com and tried that on my machine.
When I run the sample code, I get the same error. WebExcpetion is thrown and
the message is "The operation has timed-out."

Any ideas? The code I wrote is below. It's very simple and is just supposed
to go to my local home page (http://localhost/MyWebApplication), scrape the
contents, load it up into a string, and return a page telling me
the length of the string and the contents scraped from my homepage.

Here is my code:
Private Function Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Try

If Not Page.IsPostBack Then

Dim strResponse As String
Dim strURL As String = "http://localhost/MyWebApplication/"

Dim objRequest As HttpWebRequest
objRequest = CType(WebRequest.Create(strURL), HttpWebRequest)

'if this line is uncommented then this app will hang
indefinately
'objRequest.Timeout = -1

Dim objResponse As HttpWebResponse
objResponse = CType(objRequest.GetResponse(), HttpWebResponse)

Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
strResponse = sr.ReadToEnd()

sr.Close()
objResponse.Close()
objRequest.Abort()

Response.Write("The scraped contents length is:" &
strResponse.Length.ToString() & "<br><br>")
Response.Write(strResponse)

End If

Catch ex As Exception
'error accessing website
Response.Write(ex.Message)

End Try

End Function

No matter what code I run (this code, or the www.gotdotnet.com sample), the
problem always occurs in
System.Net.Http.WebRequest.GetResponse().

Here is the exact exception message from the event log.

Event Type: Error
Event Source: ExceptionManagerPublishedException
Event Category: None
Event ID: 0
Date: 12/19/2003
Time: 3:02:07 PM
User: N/A
Computer: THEBES
Description:

General Information
*********************************************
Additional Info:
ExceptionManager.MachineName: THEBES
ExceptionManager.TimeStamp: 12/19/2003 3:02:07 PM
ExceptionManager.FullName: Microsoft.ApplicationBlocks.ExceptionManagement,
Version=1.0.1448.24376, Culture=neutral, PublicKeyToken=null
ExceptionManager.AppDomainName:
/LM/W3SVC/1/Root/MyWebApplication-3-127163624072300000
ExceptionManager.ThreadIdentity:
ExceptionManager.WindowsIdentity: THEBES\ASPNET

1) Exception Information
*********************************************
Exception Type: System.Exception
Message: An unhandled exception was passed to the application object.
TargetSite: NULL
HelpLink: NULL
Source: NULL

2) Exception Information
*********************************************
Exception Type: System.Web.HttpUnhandledException
ErrorCode: -2147467259
Message: Exception of type System.Web.HttpUnhandledException was thrown.
TargetSite: Boolean HandleError(System.Exception)
HelpLink: NULL
Source: System.Web

StackTrace Information
*********************************************
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain()
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication+IExecutionSte
p.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

3) Exception Information
*********************************************
Exception Type: System.Net.WebException
Status: Timeout
Response: NULL
Message: The operation has timed-out.
TargetSite: System.Net.WebResponse GetResponse()
HelpLink: NULL
Source: System

StackTrace Information
*********************************************
at System.Net.HttpWebRequest.GetResponse()
at ASP.Test_aspx.readHtmlPage(String url) in
C:\Projects\MyWebApplication\Test.aspx:line 13
at ASP.Test_aspx.Page_Load(Object Src, EventArgs E) in
C:\Projects\MyWebApplication\Test.aspx:line 5
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

I believe the problem is in the configuration of this machine or some other
install-oriented issue that I have been unable to
solve.

The machine is a Pentium IV 2.0 Mhz w/ 256MB of RAM, and plenty of free HD
space.
I'm running Windows XP Pro with SP1 and IE 6.0 (required by .NET).

Thanks for your help in advance.

Jeff B
Senior System Architect
AAON, Inc.
Nov 18 '05 #1
1 12560
Hi Jeff,

Is it possible you're going through a Proxy Server and not specifying the
proxy? Your IE connection settings aren't automatically pushed into the
HttpWebRequest code.

When you get this timeout does it actually hang for a while before timing
out? THere is a timeout setting on the HttpWebRequest object.

You might also want to see if you can read just a small chunk first. I've
seen some issues with some Apache Servers and HTTP Chunking that can cause
problems. Read the stream in small chunks of a few bytes and see what you
get back if anything...
+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/blog/
----------------------------------
Making waves on the Web
"Jeff B" <je*******@hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP11.phx.gbl...
I'm trying to create a simple screen scraping application and I kept
getting a System.Net.WebException thrown back with a message of "The
operation has timed-out." At first I thought it was some kind of
connectivity issue on the machine. It didn't make sense though, because I
can open up a browser on the same machine and easily browse
the web.

I'm stumped. I looked over my code for any errors and just couldn't find
what I was doing wrong. So, I went out and
found a code sample from www.gotdotnet.com and tried that on my machine.
When I run the sample code, I get the same error. WebExcpetion is thrown and the message is "The operation has timed-out."

Any ideas? The code I wrote is below. It's very simple and is just supposed to go to my local home page (http://localhost/MyWebApplication), scrape the contents, load it up into a string, and return a page telling me
the length of the string and the contents scraped from my homepage.

Here is my code:
Private Function Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Try

If Not Page.IsPostBack Then

Dim strResponse As String
Dim strURL As String = "http://localhost/MyWebApplication/"

Dim objRequest As HttpWebRequest
objRequest = CType(WebRequest.Create(strURL), HttpWebRequest)

'if this line is uncommented then this app will hang
indefinately
'objRequest.Timeout = -1

Dim objResponse As HttpWebResponse
objResponse = CType(objRequest.GetResponse(), HttpWebResponse)

Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
strResponse = sr.ReadToEnd()

sr.Close()
objResponse.Close()
objRequest.Abort()

Response.Write("The scraped contents length is:" &
strResponse.Length.ToString() & "<br><br>")
Response.Write(strResponse)

End If

Catch ex As Exception
'error accessing website
Response.Write(ex.Message)

End Try

End Function

No matter what code I run (this code, or the www.gotdotnet.com sample), the problem always occurs in
System.Net.Http.WebRequest.GetResponse().

Here is the exact exception message from the event log.

Event Type: Error
Event Source: ExceptionManagerPublishedException
Event Category: None
Event ID: 0
Date: 12/19/2003
Time: 3:02:07 PM
User: N/A
Computer: THEBES
Description:

General Information
*********************************************
Additional Info:
ExceptionManager.MachineName: THEBES
ExceptionManager.TimeStamp: 12/19/2003 3:02:07 PM
ExceptionManager.FullName: Microsoft.ApplicationBlocks.ExceptionManagement, Version=1.0.1448.24376, Culture=neutral, PublicKeyToken=null
ExceptionManager.AppDomainName:
/LM/W3SVC/1/Root/MyWebApplication-3-127163624072300000
ExceptionManager.ThreadIdentity:
ExceptionManager.WindowsIdentity: THEBES\ASPNET

1) Exception Information
*********************************************
Exception Type: System.Exception
Message: An unhandled exception was passed to the application object.
TargetSite: NULL
HelpLink: NULL
Source: NULL

2) Exception Information
*********************************************
Exception Type: System.Web.HttpUnhandledException
ErrorCode: -2147467259
Message: Exception of type System.Web.HttpUnhandledException was thrown.
TargetSite: Boolean HandleError(System.Exception)
HelpLink: NULL
Source: System.Web

StackTrace Information
*********************************************
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain()
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication+IExecutionSte p.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

3) Exception Information
*********************************************
Exception Type: System.Net.WebException
Status: Timeout
Response: NULL
Message: The operation has timed-out.
TargetSite: System.Net.WebResponse GetResponse()
HelpLink: NULL
Source: System

StackTrace Information
*********************************************
at System.Net.HttpWebRequest.GetResponse()
at ASP.Test_aspx.readHtmlPage(String url) in
C:\Projects\MyWebApplication\Test.aspx:line 13
at ASP.Test_aspx.Page_Load(Object Src, EventArgs E) in
C:\Projects\MyWebApplication\Test.aspx:line 5
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

I believe the problem is in the configuration of this machine or some other install-oriented issue that I have been unable to
solve.

The machine is a Pentium IV 2.0 Mhz w/ 256MB of RAM, and plenty of free HD
space.
I'm running Windows XP Pro with SP1 and IE 6.0 (required by .NET).

Thanks for your help in advance.

Jeff B
Senior System Architect
AAON, Inc.

Nov 18 '05 #2

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

Similar topics

5
by: japslam japslam via DotNetMonster.com | last post by:
Hi all, I have problem when I use HttpWebRequest and take long time to call to my service server. If at that time there are many request comes in semultaneous, I will get this exception ...
2
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get...
2
by: GlennLanier | last post by:
Hello, I've searched the forums and can't find an answer -- if it i there, kindly point me in that direction. I would like to simulate a browser POSTing a FORM and be able to pars the response....
0
by: Veerle | last post by:
Hi, On the website of the Belgian lottery, you can download an excel sheet with lottery results (the winning numbers) over the years and an excel sheet with financial results (the winnings) over...
2
by: microdevsolutions | last post by:
Hello I've seen examples to read a file from somewhere into a HttpWebRequest object then write it to a HttpWebResponse object then stream it into a Stream object, very similar to the following...
1
by: MikeZ | last post by:
I post this question last week, no good answer, so I post again. Sorry about this. I use WebRequest.Create/WebRequest.GetResponse to handle HTTP request in a VS2003 project. I got HTTP violation...
1
by: Morgan Cheng | last post by:
When the function HttpWebRequest.GetResponse() is called, what happened? I mean, does this function return till all HTTP response is downloaded to local machine? or only HTTP header part retrived...
4
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi, I've run into a set of errors I don't understand coming back from HttpWebRequest.GetResponse, In one case, null is returned from the request without an Exception and in the other the request...
3
by: FreddyMack | last post by:
Two questions: 1) In Silverlight 4.0 Beta, I cannot find HttpWebRequest.GetResponse() ... any ideas where the functionality may be? I have found the Async form, but not the Sync form. 2) Within...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.