C# Webclient and Proxy Server

How to bypass the system proxy when using WebClient

You can use this

WebClient webclient = new WebClient();
webclient.Proxy = null;

it will resolve your issue

Using C# WebClient with a Proxy - no request made to proxy server?

It turns out that FreeProxy wasn't accepting HTTPS traffic.

I guess the proxy must return the types of traffic it can route, and if it cannot, the webclient does nothing.

Switched to using the Burp suite as our proxy since it can accept HTTPS.

http://portswigger.net/burp/

How to check if proxy settings in WebClient work?

If I understand your question:

You could set up a Proxy Server on your computer, such as CCProxy (Or something similar). Point your WebClient application to that proxy server. Then enable logging on CCProxy to see if the traffic you expected is passing through.

EDIT

Are you in a network that restricts internet access unless you are using a proxy server?

If your network supports it, you could look into Automatic Proxy Detection https://msdn.microsoft.com/en-us/library/fze2ytx2(v=vs.110).aspx

When automatic proxy detection is enabled, the system attempts to locate a proxy configuration script that is responsible for returning the set of proxies that can be used for the request. If the proxy configuration script is found, the script is downloaded, compiled, and run on the local computer when proxy information, the request stream, or the response is obtained for a request that uses a WebProxy instance.

The reason it is hard to know if the problem is proxy settings is; when your app tries to connect to the internet, it cannot possibly know or guess that the reason the URL is not accessible is because you need to use a proxy. So it throws a general exception. Because there are many reasons why a URL might not be accessible, such as, Internet service is down, network misconfiguration, or like in your case, a proxy setting is required. Your app would be guessing as to which one of those reasons the URL is inaccessible.

How to get proxy info from WebClient object?

Proxy Uri is context bind, with other words for different original request a proxy configuration can provide different proxy Uris. To get an actual proxy Uri (Host, Port, Protocoll, etc) you must provide the original Uri

Uri proxyUri = yourWebClient.Proxy.GetProxy(new Uri(originalRequestUrl))

or

Uri proxyUri = yourWebClient.Proxy.GetProxy(originalRequestUri)

then you can use the proxyUri variable's properties like Host, Port etc.

Note: If you get back the original Uri that means: There was no proxy in effect.

In case if providing the original request Uri is a problem for you, and you are sure the proxy is identical for all Uris, then ypi cam simply provide a dummmy (but valid) uri (although this is an ugly solution) like :

Uri proxyUri = yourWebClient.Proxy.GetProxy(new Uri("http://www.google.com"))

Obviously this will not cause traffic to www.google.com, just getting the proxy configuration.

About the credentials the same story:

 NetworkCredential credential  = yourWebClient.Proxy.Credentials.GetCredential(...)

Via the credential variable you get the Domain, UserName and Password* properties.

(*Just for the record: Logging password is not a recommended practice)



Related Topics



Leave a reply



Submit