微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我试图使用 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解释如何处理它.

原文地址:https://www.jb51.cc/csharp/100910.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐