c# - 如何使 System.Net.WebProxy 不绕过本地 url?

标签 c# .net proxy restsharp webproxy

我正在尝试制作 FiddlerRestSharp 一起工作女巫使用 System.Http.WebProxy,所以我希望将其设置为 localhost:8888127.0.0.1:8888

代码如下:

    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);

输出:

MSDN 声明如下:

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.

我不明白为什么在我的例子中它返回 true,这是一个错误吗?那怎么让它工作呢?谢谢!

最佳答案

这是 .Net 框架中 HTTP 客户端库实现中的硬编码行为,反射(reflect)了 Internet Explorer 9 之前的 WinInet 行为。

参见 Monitor traffic to localhost from IE or .NET来自 Fiddler 网站的解释了如何处理它。

关于c# - 如何使 System.Net.WebProxy 不绕过本地 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12378638/

相关文章:

c# - 什么是 x-wmapp2 和 x-wmapp1?

c# - 集合和列表

.net - 将 Sql-Server (express) 从命名实例更改为 localhost?

.net - 多线程中读写隔离

docker - Kubernetes无法提取图像k8s.gcr.io

c# - 流畅的 NHibernate 使用 nvarchar(max) 自动映射字符串列表

c# - EF Core 级联删除速度?

c# - 失去焦点时窗口闪烁?

node.js - 代理背后的socket.io客户端在浏览器中工作正常,而不是在nodejs应用程序中

android - 类型错误 :Request path contains unescaped characters - npm & cordova