加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何使System.Net.WebProxy不绕过本地URL?

发布时间:2020-12-15 08:09:12 所属栏目:百科 来源:网络整理
导读:我试图使用 RestSharp使用System.Http.WebProxy使 Fiddler工作,所以我希望它设置为localhost:8888或127.0.0.1:8888 这是代码: var webProxy = new WebProxy(new Uri("http://127.0.0.1:8888")) { BypassProxyOnLocal = false }; var bypassed = webProxy.I
我试图使用 RestSharp使用System.Http.WebProxy使 Fiddler工作,所以我希望它设置为localhost:8888或127.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);

输出:true

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客户端库实现中的硬编码行为,反映了Internet Explorer 9之前WinInet的行为.

请参阅Fiddler网站上的Monitor traffic to localhost from IE or .NET解释如何处理它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读