为什么 WebProxy BypassProxyOnLocal 对我不起作用?
我试图获取从 C# .NET 到本地地址 (localhost:3000) 的 HTTP 调用,以使用我设置的代理(这样我就可以通过 fiddler)。如果我将目标 URL 指向非本地地址,则可以使用下面的 WebProxy 方法,但是我需要将其指向我拥有的本地 Web 服务器(位于 localhost:3000),并且当我这样做时,请求不会继续通过代理。
我已包含“proxyObject.BypassProxyOnLocal = false”。这应该可以让它工作吧?关于如何强制请求通过 WebProxy 以进行针对本地地址的 http 调用,有什么建议吗?
WebProxy proxyObject = new WebProxy("http://localhost:8888/", false);
proxyObject.Credentials = new NetworkCredential();
proxyObject.BypassProxyOnLocal = false;
WebRequest.DefaultWebProxy = proxyObject;
var request = (HttpWebRequest)WebRequest.Create(targetUri);
// I also included this line as a double check
request.Proxy = proxyObject;
然而,后续调用不会通过代理,例如我这样做时:
var res = (HttpWebResponse)req.GetResponse();
谢谢
I'm trying to get HTTP calls I'm making from C# .NET to a local address (localhost:3000) to use the proxy I set (so I can go through fiddler). Using the below WebProxy approach works if I point the target URL to a non-local address, however I need to point it to a local web-server I have (at localhost:3000), and when I do this the request is not going through the proxy.
I have inlcuded the "proxyObject.BypassProxyOnLocal = false". This should make it work no? Any suggestions re how to force the request to go through the WebProxy for http calls targetting a local address?
WebProxy proxyObject = new WebProxy("http://localhost:8888/", false);
proxyObject.Credentials = new NetworkCredential();
proxyObject.BypassProxyOnLocal = false;
WebRequest.DefaultWebProxy = proxyObject;
var request = (HttpWebRequest)WebRequest.Create(targetUri);
// I also included this line as a double check
request.Proxy = proxyObject;
Subsequent calls do not go through the proxy however, such as when I do:
var res = (HttpWebResponse)req.GetResponse();
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只需在本地主机上添加一个“点”即可解决此问题,因此我尝试访问“本地主机”,而不是访问“本地主机”。 (注意主机名末尾的点)
应得的信用:
我从这个线程 http://www.west-wind.com/weblog/posts/2009/Jan/14/Monitoring-HTTP-Output-with-Fiddler-in -NET-HTTP-Clients-and-WCF-Proxies#596591
工作正常!
I get around this simply by appending a "dot" to localhost, so instead of accessing "localhost", I try to access "localhost." (notice the dot at the end of the hostname)
Credit where credit is due:
I got this unusual tip from this thread http://www.west-wind.com/weblog/posts/2009/Jan/14/Monitoring-HTTP-Output-with-Fiddler-in-NET-HTTP-Clients-and-WCF-Proxies#596591
Works fine!
请参阅 https://docs.telerik.com/fiddler/observe-traffic 的说明/故障排除/nottraffictolocalhost
See explanation on https://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost