SirCaleb
asked on
System.Net.WebClient w/ Proxy Servers
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. CheckFinal Status()
at System.Net.HttpWebRequest. EndGetResp onse(IAsyn cResult asyncResult)
at System.Net.HttpWebRequest. GetRespons e()
at System.Net.WebClient.Downl oadFile(St ring 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("myPro xyServer", 8080)
proxyObject.BypassProxyOnL ocal = True
proxyObject.Credentials = System.Net.CredentialCache .DefaultCr edentials
ws.Proxy = proxyObject
Surprising that the System.Net.WebClient does not support this same member.
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.
at System.Net.HttpWebRequest.
at System.Net.HttpWebRequest.
at System.Net.WebClient.Downl
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("myPro
proxyObject.BypassProxyOnL
proxyObject.Credentials = System.Net.CredentialCache
ws.Proxy = proxyObject
Surprising that the System.Net.WebClient does not support this same member.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.BypassProxyOnL ocal = True
proxyObject.Credentials = CredentialCache.DefaultCre dentials
GlobalProxySelection.Selec t = proxyObject
Thanks for the help.
Dim proxyObject As New WebProxy("myServer", 8080)
proxyObject.BypassProxyOnL
proxyObject.Credentials = CredentialCache.DefaultCre
GlobalProxySelection.Selec
Thanks for the help.
correct.
The ones on the webclient would override this.
The ones on the webclient would override this.
ASKER
It's still not authenticating on the proxy server ...
Dim wc As New System.Net.WebClient
wc.Credentials = System.Net.CredentialCache
wc.DownloadFile(DownloadUR
returns:
System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
at System.Net.HttpWebRequest.
at System.Net.HttpWebRequest.
at System.Net.HttpWebRequest.
at System.Net.WebClient.Downl
I am using the credentialcache in the exact same way for the web services and it fixed them ... but not the webclient. Ideas?