Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27196

HTTP Web Request

$
0
0
I am wanting to create a HTTP web request with a time out so that my program isn't delayed several minutes trying to connect to a website if it isn't online.

What I am currently doing is downloading strings from a plain txt file which is on my local host and I am doing this with webclient.downloadstring.

But the webclient doesn't have a timeout function so the only other thing is to make a timer but the thing is because I am downloading the string during the form load process the timer doesn't function after the form is loaded, so that doesn't work for me.

So I was thinking is it possible to use a http web request with a time out on the form load event and then when it times out, I could continue with something else.

This is the basic http web request:

vb.net Code:
  1. Dim myWebRequest As Net.HttpWebRequest
  2.         Dim myWebResponse As Net.HttpWebResponse
  3.  
  4.         myWebRequest = Net.WebRequest.Create("http://127.0.0.1")
  5.         myWebRequest.Timeout = 2000
  6.         myWebRequest.KeepAlive = True
  7.         myWebRequest.Credentials = Net.CredentialCache.DefaultCredentials
  8.         myWebResponse = myWebRequest.GetResponse()
  9.         myWebResponse.Close()

But then how would I create an if condition knowing it's timed out? "If myWebRequest.Timeout = 2000"?

Viewing all articles
Browse latest Browse all 27196

Trending Articles