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解释如何处理它.

相关文章

原文地址:http://msdn.microsoft.com/en-us/magazine/cc163...
前言 随着近些年微服务的流行,有越来越多的开发者和团队所采...
最近因为比较忙,好久没有写博客了,这篇主要给大家分享一下...
在多核CPU在今天和不久的将来,计算机将拥有更多的内核,Mic...
c语言输入成绩怎么判断等级
字符型数据在内存中的存储形式是什么