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

牧云@^-^@ 提交于 2019-12-23 08:30:56

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/12378638/how-to-make-system-net-webproxy-to-not-bypass-local-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!