Can't get HttpWebResponse to work - timeout or connection closed

G

Guest

Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I
get "The operation has timed-out". I'm simply trying to send an HTTP request
querystring to a remote website and read back the single string it returns
(OK/Not-Ok)! It seems such a simple thing to do, but I've been on this for
hours now!

Here's the code I'm trying:

Dim myRequest As HttpWebRequest
Dim myResponse As HttpWebResponse
Dim sr As StreamReader

myRequest = CType(WebRequest.Create("http://www.microsoft.com"),
HttpWebRequest)
myRequest.ContentType = "application/x-www-form-urlencoded"
myResponse = CType(myRequest.GetResponse(), HttpWebResponse)
sr = New StreamReader(myResponse.GetResponseStream())

I've also tried an alternative which I found on the www.asp.net forum:

Dim objClient As New WebClient
Dim objStream As Stream = objClient.OpenRead("http://www.microsoft.com")
Dim objRead As New StreamReader(objStream)
Response.Write(Server.HtmlEncode(objRead.ReadToEnd))

And I get exactly the same results.

Any help would be gratefully received!!

Noggin
 
V

V.Balaji

Hi,



use the code below i have added the red line(timeout code). it works fine to me.

Rgs

***********************************************************************

Dim myRequest As HttpWebRequest

Dim myResponse As HttpWebResponse

Dim sr As StreamReader



myRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest)

myRequest.Timeout = 10000

myRequest.ContentType = "application/x-www-form-urlencoded"

myResponse = CType(myRequest.GetResponse(), HttpWebResponse)

sr = New StreamReader(myResponse.GetResponseStream())

'I() 've also tried an alternative which I found on the www.asp.net forum:

Dim objClient As New WebClient

Dim objStream As Stream = objClient.OpenRead("http://www.microsoft.com")

Dim objRead As New StreamReader(objStream)

MsgBox(objRead.ReadToEnd)

*********************************************************************************************************
 
G

Guest

Hi,

That still doesn't work for me! I'm wondering if it's because I'm working
inside a VMware virtual machine (though everything else works internet-wise!)
I'll give it a go on another machine without VMware.

Thanks for your help!

Noggin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top