473,385 Members | 1,890 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,385 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 6446
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.