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

accessing URLs outside firewall with WebClient? error: The underlying connection was closed

For some reason I can't get a WebClient to access an outside URL from
behind our firewall. The code works when it runs outside the firewall.

I turned on windows authentication in the web.config
<authentication mode="Windows" />
and set up IIS to not allow anonymous access.

My browser is set up to auto detect the proxy server, so IE/Firefox can
access outside pages, so I added code to auto-detect the proxy server.

But still the function returns the error:
"The underlying connection was closed: Unable to connect to the remote
server."

Can someone explain how to get it to work from behind our firewall? My
code is below.

Thanks in advance...

'goto a URL and retrieve text from page
Private Function GetHtml(byval sURL as String) As String
Dim WebClient As New System.Net.WebClient
Dim webResponse As IO.Stream
Dim webResult As String
Dim myReader As IO.StreamReader
Try
'problem with credentials? attemt #1
'TODO: redo this to automatically detect if "anonymous access"
is enabled in IIS
'If
System.Configuration.ConfigurationSettings.AppSett ings.Get("AnonymousAccessEnabled")
<"1" Then
' WebClient.Credentials =
System.Web.HttpContext.Current.User.Identity
' ' ' System.Web.HttpContext.Current.User.Identity
' ' 'WebClient.Credentials =
' ' 'System.Net.ICredentials
'End If

'access web thru proxy:
'GlobalProxySelection.Select = New WebProxy("proxy", 8080)
GlobalProxySelection.Select = WebProxy.GetDefaultProxy

webResponse = WebClient.OpenRead(remoteFile)
'objWebClient.DownloadData (strURL)

myReader = New IO.StreamReader(webResponse)
webResult = myReader.ReadToEnd
myReader.Close()
webResponse.Close()

Return webResult
Catch ex As Exception
HandleWebError(ex)
End Try
End Function ' GetHtml

Dec 7 '06 #1
1 6429
Try explicitly setting the url, port, username and password of your proxy,
and assign that to the Proxy property of the WebClient.
Thanks for your reply... I tried this and am still getting an error:
"The underlying connection was closed: Unable to connect to the remote
server."

Here is the code...

'goto a URL and retrieve text from page
Private Function GetHtml(byval sURL as String) As String
Dim WebClient As New System.Net.WebClient
Dim webResponse As IO.Stream
Dim webResult As String
Dim myReader As IO.StreamReader
Try
GlobalProxySelection.Select = New WebProxy("111.11.111.111", 8080)
'WebClient.Credentials = New NetworkCredential("myuser", "mypass")
WebClient.Credentials = New NetworkCredential("mydomain/myuser",
"mypass")
webResponse = WebClient.OpenRead(remoteFile)
myReader = New IO.StreamReader(webResponse)
webResult = myReader.ReadToEnd
myReader.Close()
webResponse.Close()
Return webResult
Catch ex As Exception
HandleWebError(ex)
End Try
End Function ' GetHtml
-----
Peter wrote:
Try explicitly setting the url, port, username and password of your proxy,
and assign that to the Proxy property of the WebClient.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mad Scientist Jr" wrote:
For some reason I can't get a WebClient to access an outside URL from
behind our firewall. The code works when it runs outside the firewall.

I turned on windows authentication in the web.config
<authentication mode="Windows" />
and set up IIS to not allow anonymous access.

My browser is set up to auto detect the proxy server, so IE/Firefox can
access outside pages, so I added code to auto-detect the proxy server.

But still the function returns the error:
"The underlying connection was closed: Unable to connect to the remote
server."

Can someone explain how to get it to work from behind our firewall? My
code is below.

Thanks in advance...

'goto a URL and retrieve text from page
Private Function GetHtml(byval sURL as String) As String
Dim WebClient As New System.Net.WebClient
Dim webResponse As IO.Stream
Dim webResult As String
Dim myReader As IO.StreamReader
Try
'problem with credentials? attemt #1
'TODO: redo this to automatically detect if "anonymous access"
is enabled in IIS
'If
System.Configuration.ConfigurationSettings.AppSett ings.Get("AnonymousAccessEnabled")
<"1" Then
' WebClient.Credentials =
System.Web.HttpContext.Current.User.Identity
' ' ' System.Web.HttpContext.Current.User.Identity
' ' 'WebClient.Credentials =
' ' 'System.Net.ICredentials
'End If

'access web thru proxy:
'GlobalProxySelection.Select = New WebProxy("proxy", 8080)
GlobalProxySelection.Select = WebProxy.GetDefaultProxy

webResponse = WebClient.OpenRead(remoteFile)
'objWebClient.DownloadData (strURL)

myReader = New IO.StreamReader(webResponse)
webResult = myReader.ReadToEnd
myReader.Close()
webResponse.Close()

Return webResult
Catch ex As Exception
HandleWebError(ex)
End Try
End Function ' GetHtml
Dec 8 '06 #2

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

Similar topics

4
by: Justin Malloy | last post by:
I am using the System.Net.Webclient to try and download an XML file from a website but am receiving a HTTP protocol error when running the DownloadFile() sub routine. I did a HTTP trace using...
2
by: John | last post by:
My firewall appears to be blocking an RSS XML feed from being returned even thought port 80 is enabled. Can anyone help? Dim proxyURI As New Uri("http://MyIP:80") GlobalProxySelection.Select =...
2
by: Gary Short | last post by:
Hello group, I was wondering if anyone here could help me with an odd WebClient problem. When I run the following code: WebClient aWebClient = new WebClient(); Byte aBA =...
1
by: yyy | last post by:
This problem bothers me for a long time: I use WebClient.DownloadData in order to read text from an HTML document this way: WebClient c = new WebClient(); string html=...
5
by: Helen | last post by:
Hi, I am trying to write an ASP.Net application that integrates with a third party application via their fairly simplistic web component, however I am having problems with the URI. The URI...
0
by: Kumar | last post by:
Hi all, I have the following code which uses WebClient.UploadValues myNameValueCollection.Add("Name", name) myNameValueCollection.Add("Age", age) .............. ............. Dim web As New...
0
by: Nate Hekman | last post by:
I've been trying to use WebClient to download a file from an ftp server, but kept getting this exception during the call to DownloadData: An existing connection was forcibly closed by the remote...
1
by: matt | last post by:
hello, i am using a .NET 1.1 winform to perform webrequests via the System.Net.WebClient class (not a webservice, actually). It uploads values via a POST command & a URL, then receives the html...
1
by: Deepson Thomas | last post by:
Hi, Iam trying to use WebClient class under system.net namespace to download files from internet via http. For that iam using DownloadFile method. But when ever iam trying to download any file...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.