Solved

System.Net.WebClient w/ Proxy Servers

Posted on 2004-04-30
4
2,660 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
correct.

The ones on the webclient would override this.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now