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

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

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
Nov 19 '05 #1
2 2585
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)

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

"Noggin The Nog" <No**********@discussions.microsoft.com> wrote in message news:A8**********************************@microsof t.com...
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

Nov 19 '05 #2
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

"V.Balaji" wrote:
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)

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

"Noggin The Nog" <No**********@discussions.microsoft.com> wrote in message news:A8**********************************@microsof t.com...
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

Nov 19 '05 #3

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

Similar topics

5
by: Martin | last post by:
Dear Group Sorry for posting this here. I'm desperate for a solution to this problem and thought some of you might have come across it with .NET and SQL Server. Let's assume I've the following...
3
by: Kamalanathan T. | last post by:
Hi, We have developed an Web application in ASP.NET with C# and we r using SQL Server 2000. We get the Timeout expired error, when more than 300 concurrent users hit the site. I hagone thru...
4
by: Guoqi Zheng | last post by:
Dear sir, I keep getting the following errors on one of my sites after clicking for many times. Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This...
1
by: Brent | last post by:
I thought I was doing a simple thing, here -- asking a server for a text document, getting the first 150 lines, and then returning the lines. But I keep getting timeout errors: "Exception...
2
by: Brad Wood | last post by:
<environment> Consuming a web service from a VS2005 beta 2 test harness on WinXP. Web service built with VS2003 running on my machine with IIS 5X set to use ASP.NET 1.1 </environment> I have...
1
by: daz_oldham | last post by:
Hi I have a method (very bottom of this post) which I am using for doing XMLRPC calls. This works fine locally in Cassini (debug mode in VS2005, WinXP SP2), however when I run this on my...
2
by: Earl | last post by:
After I run the debugger awhile on the same app (change, run, change, run, etc. ad nauseaum), I start getting timeout errors on connection. I'm speculating that the connection pool is being used up...
6
by: TheSteph | last post by:
Hi, (using C#, VS2005, .NET 2.0.) I sometimes need to access my database (SQL Server) in SINGLE_USER mode.
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
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.