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

I'm 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 declares the following:

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

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

IsBypassed returns true in any of the following conditions:

  • If BypassProxyOnLocal is true and host is the local URI. Local requests are determined by the absence of a period (.) In the URI, as in "HTTP: // web server /".

  • If the host matches the regex in BypassList.

  • If the address is null.

All other conditions return false .

I do not understand why in my case it returns true , is this an error? How to do it? Thanks!

+6
source share
1 answer

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

See Tracking traffic to a local host from IE or .NET from the Fiddler website for an explanation of how to deal with this.

+6
source

Source: https://habr.com/ru/post/925174/


All Articles