Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System.Net.WebClient w/ Proxy Servers

Posted on 2004-04-30
4
Medium Priority
?
2,707 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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