System.Net.HttpWebRequest - Unable to connect to the remote server

T

tbdean

I'm having a bit of a problem with System.Net.HttpWebRequest. I've also
tried Net.WebClient with the same results.

The odd thing is that this works fine in the IDE, it's just once I
build and run from the EXE that it give me the problem.

Here is my code:

'Create web request object
Dim webRequest As System.Net.HttpWebRequest
webRequest =
System.Net.HttpWebRequest.Create("http://ip.addr.ess:port/page?data=" &
XML)
webRequest.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy()
webRequest.KeepAlive = False

'Set user agent
webRequest.UserAgent = "ourname - HTTPWebRequest"

'Add authorization header
Dim CredCache As System.Net.CredentialCache
CredCache = New System.Net.CredentialCache
CredCache.Add(New Uri("ip.addr.ess"), "Basic", New
System.Net.NetworkCredential("ourname", "ourpassword"))
webRequest.PreAuthenticate = True
webRequest.Credentials = CredCache
CredCache = Nothing

'Send / get resonse
Dim objStream As System.IO.Stream

'Error comes here after about 30 seconds:
objStream = webRequest.GetResponse.GetResponseStream

The error is "The underlying connection was closed: Unable to connect
to the remote server." I've tried it with other URLs and it works fine.
I've even tried it with IP only URLs, and IP only URLs with non
standard ports, and it still works. I've even tried setting up my local
copy of IIS to forward to this IP, and have this code connect to
"localhost". That actually worked, but I couldn't get the
authentication header to go through.

The server I'm trying to connect to is on a non-standard port, on a
private IP space, behind a firewall. But like I said, it works fine in
the IDE.

Thanks so much to anyway that can helP!
 
T

tbdean

nm, I'm an idiot. I wrote this great code that automatically switches
the URL based on whether or not we're running from the IDE. Of course,
we don't have access to the production server yet and I totaly forgot
about that URL switching code.

Thanks anyhow. Anyone know how to get this to work?
System.Time.Reclaim(System.Time.Units.Last4Hours)
 
G

Guest

I had a similar problem. But my app was working for a year and just stopped.
I noticed that you were setting the HTTP Useragent and I wasn't. I set it and
it works now. I guess the "black hole" turned on this requirement on the
proxy server. Thanks for posting your code.
 

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