Solved

System.Net.WebClient w/ Proxy Servers

Posted on 2004-04-30
4
2,677 Views
Last Modified: 2012-06-22
I cannot seem to find a way to make the system.net.webclient work through a proxy server.  Web Services has a proxy member but webclient does not ... odd.

Anyone have any reasonable idea on how to make the System.Net.WebClient work through a proxy server?

Dim wc As New System.Net.WebClient
wc.DownloadFile("http://www.something.com/whatever.txt", "C:\whatever.txt")

Doing this through a proxy throws the following exception:

System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
   at System.Net.HttpWebRequest.CheckFinalStatus()
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.HttpWebRequest.GetResponse()
   at System.Net.WebClient.DownloadFile(String address, String fileName)

I have Web Services working through proxies with the following code ...

Dim ws As com.whatever.www.myWebService
Dim proxyObject As New System.Net.WebProxy("myProxyServer", 8080)
proxyObject.BypassProxyOnLocal = True
proxyObject.Credentials = System.Net.CredentialCache.DefaultCredentials
ws.Proxy = proxyObject

Surprising that the System.Net.WebClient does not support this same member.
0
Comment
Question by:SirCaleb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 10964122
if you use the WebRequest directly you have access to this.

Also you can set the GlobalProxy for use through here.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetglobalproxyselectionclasstopic.asp
0
 
LVL 2

Author Comment

by:SirCaleb
ID: 10977282
Hrm, that did not fix my problem :(

It's still not authenticating on the proxy server ...

Dim wc As New System.Net.WebClient
wc.Credentials = System.Net.CredentialCache.DefaultCredentials
wc.DownloadFile(DownloadURL, DownloadPath)

returns:

System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
   at System.Net.HttpWebRequest.CheckFinalStatus()
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.HttpWebRequest.GetResponse()
   at System.Net.WebClient.DownloadFile(String address, String fileName)

I am using the credentialcache in the exact same way for the web services and it fixed them ... but not the webclient.  Ideas?
0
 
LVL 2

Author Comment

by:SirCaleb
ID: 10977724
Actually, that did work but MSDN needs to update their documentation.  If you use the globalproxyselection, you have to set the credentials there and not on the webservice or webclient objects:

Dim proxyObject As New WebProxy("myServer", 8080)
proxyObject.BypassProxyOnLocal = True
proxyObject.Credentials = CredentialCache.DefaultCredentials
GlobalProxySelection.Select = proxyObject

Thanks for the help.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10978797
correct.

The ones on the webclient would override this.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question