Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make System.Net.WebProxy to not bypass local urls?

I am trying to make Fiddler work with RestSharp witch uses System.Http.WebProxy, so I want it to be set to localhost:8888 or 127.0.0.1:8888

Here is the code:

    var webProxy = new WebProxy(new Uri("http://127.0.0.1:8888"))
    {
        BypassProxyOnLocal = false
    };

    var bypassed = webProxy.IsBypassed(new Uri("http://127.0.0.1"));
    Console.WriteLine(bypassed);

Outputs: true

MSDN states the following:

The IsBypassed method is used to determine whether to bypass the proxy server when accessing an Internet resource.

The BypassProxyOnLocal and BypassList properties control the return value of the IsBypassed method.

IsBypassed returns true under any of the following conditions:

  • If BypassProxyOnLocal is true and host is a local URI. Local requests are identified by the lack of a period (.) in the URI, as in "http://webserver/".

  • If host matches a regular expression in BypassList.

  • If Address is null.

All other conditions return false.

I don't understand why in my case it returns true, is this a bug? How to make it work then? Thanks!

like image 597
Restuta Avatar asked Sep 11 '12 22:09

Restuta


People also ask

How to bypass LAN proxy?

To bypass the proxy, select the Bypass proxy server for local (intranet) addresses check box in the Local Area Network (LAN) Settings dialog box.

How to avoid a proxy server?

In the System section, click on Open your computer's proxy settings. On Windows 10, this will open the Proxy settings window. Under Automatic proxy setup, switch off: Automatically detect settings & Use setup script. Under Manual proxy setup, switch off: Use a proxy server, then click on Save.

What does bypass proxy mean?

The Proxy Bypass tab of the Bypass Settings page enables you to define sites that bypass the cloud service for all policies. This may include, for example, internal sites that are not accessible from the Internet, so the cloud service cannot serve or analyze them.


1 Answers

This is hard-coded behavior in the implementation of the HTTP client library in the .Net framework, mirroring the behavior of WinInet prior to Internet Explorer 9.

See Monitor traffic to localhost from IE or .NET from the Fiddler web site explains how to deal with it.

like image 133
Jeffrey Hantin Avatar answered Oct 11 '22 14:10

Jeffrey Hantin