473,386 Members | 1,817 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.

More WebRequest Timeout Questions

I use the following code to get source HTML. The second line seems to work
when I get no response from a site. However, I want to stop the request if
it's taking more than 20 - 30 seconds. I can't seem to make it work. Please
point out the mistakes that I have. Thanks

code.............
WebRequest = WebRequest.Create(URL)
WebRequest.Timeout() = RunInfo.ConnectTimeout
WebResponse = WebRequest.GetResponse 'WEBRESPONSE IS A PUBLIC OBJECT
InputReceive = WebResponse.GetResponseStream
Encoding = System.Text.Encoding.GetEncoding("utf-8")
StreamRead = New System.IO.StreamReader(InputReceive, Encoding)
HTML = StreamRead.ReadToEnd()
If (Not WebResponse Is Nothing) Then
WebResponse.Close()
more code.......

I then added the following.....

code..........
'NEW CODE
Dim aTimer As New System.Timers.Timer(RunInfo.InactivityTimeOut)
aTimer.Enabled = True
aTimer.AutoReset = False
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
'END NEW CODE
WebRequest = WebRequest.Create(URL)
WebRequest.Timeout() = RunInfo.ConnectTimeout
WebResponse = WebRequest.GetResponse
InputReceive = WebResponse.GetResponseStream
Encoding = System.Text.Encoding.GetEncoding("utf-8")
StreamRead = New System.IO.StreamReader(InputReceive, Encoding)
HTML = StreamRead.ReadToEnd()
If (Not WebResponse Is Nothing) Then
WebResponse.Close()
more code ..........

end sub

Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
ElapsedEventArgs)
WebResponse.Close()
End Sub
Nov 20 '05 #1
0 2183

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

Similar topics

5
by: C# Learner | last post by:
Is it possible to create a WebRequest instance and, instead of giving it a URI, give it an actual HTTP request? e.g.: GET / HTTP/1.1 Host: www.google.com CR LF CR LF Thanks in advance.
2
by: news.microsoft.com | last post by:
Hello I try to implement "retry" if connection to web ends with "time out". I want to give a chance to prolong waiting for response. The following code is taken from WebRequest.GetResponse()...
1
by: aaronfude | last post by:
Hi, I'm running the following code to read a URL into a string. When the url is offline, it times out after about 10 seconds regardless of what I set myRequest.Timeout to. Any suggestions? ...
3
by: Stephane | last post by:
Hi, I'm trying to use PayPal and its Instant Payment Notification. In short, when a payment is made, PayPal send a post to my server and I post it back to PayPal. I'm using WebRequest to do...
6
by: Bob | last post by:
Hi, I am new to using a web resource which is not a webservice and I am spinning my wheels with the webrequest class. I am trying to interact with a URI that has been given to me. It is say...
1
by: Christian Urbanczyk | last post by:
Hello! I have a problem with the Webrequest. I've search everywhere to find an answer but it seems that no one has the the problem before. So i hope somebody can help me here! Following Code:...
0
by: thomasabcd | last post by:
Hi, During the user's registration I wan't to geo-code an address using localsearchmaps.com/geo. For that purpose I use a webrequest like this: string url =...
3
by: Jonathan | last post by:
I appreciate anyone's insight on this as I am new to web programming with .NET. I have a simple method which I use to send various HTTP requests to a web server (snippet below). On the first...
2
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.