Solved

System.Net.WebClient w/ Proxy Servers

Posted on 2004-04-30
4
2,668 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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