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

前端之家收集整理的这篇文章主要介绍了c# – 如何使System.Net.WebProxy不绕过本地URL?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用 RestSharp使用System.Http.WebProxy使 Fiddler工作,所以我希望它设置为localhost:8888或127.0.0.1:8888

这是代码:@H_301_3@

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@H_301_3@

MSDN声明如下:@H_301_3@

The IsBypassed method is used to determine whether to bypass the proxy
server when accessing an Internet resource.@H_301_3@

The BypassProxyOnLocal and BypassList properties control the return
value of the IsBypassed method.@H_301_3@

IsBypassed returns true under any of the following conditions:@H_301_3@

  • 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/”.@H_301_3@

  • If host matches a regular expression in BypassList.@H_301_3@

  • If Address is null.@H_301_3@

All other conditions return false.@H_301_3@

我不明白为什么在我的情况下它返回true,这是一个错误吗?如何让它工作呢?谢谢!@H_301_3@

解决方法

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

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

原文链接:https://www.f2er.com/csharp/100910.html

猜你在找的C#相关文章