The underlying connection was closed: Unable to connect to the remote server.

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I have the following code:

Line 35: Dim sURL As String = "http://www.google.com"
Line 36: Dim data As Stream =
client.OpenRead(Server.UrlPathEncode(sURL))
Line 37: Dim reader As New StreamReader(data)
Line 38: Results = reader.ReadToEnd()

I get an error on Line 36, Exception Details: System.Net.WebException:
The underlying connection was closed: Unable to connect to the remote
server.

The stack trace is below:
[WebException: The underlying connection was closed: Unable to connect
to the remote server.]
System.Net.HttpWebRequest.CheckFinalStatus()
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
System.Net.HttpWebRequest.GetResponse()
System.Net.WebClient.OpenRead(String address)
AtomzSearchPOC.Result.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\GoogleTest\Result.aspx.vb:36
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Any help on resolving this issue would be appreciated
 
Google, and many other sites, will reject a connection from an app that
doesn't identify the browser that is connecting to it. There are a few
headers that you really should put on the request if you expect Google to
think that you are hitting from a browser. Try putting in a UserAgent
header, and experiment with other headers as well.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Back
Top