为什么不会WebProxy BypassProxyOnLocal工作给我吗? [英] why won't WebProxy BypassProxyOnLocal work for me?

查看:362
本文介绍了为什么不会WebProxy BypassProxyOnLocal工作给我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让HTTP调用,我从C#.net制作到本地地址(本地主机:3000)使用我设置代理(这样我就可以通过小提琴手)。使用下面的WebProxy方式的作品,如果我点的目标URL到非本地地址,但我需要把它指向本地Web服务器我(在本地主机:3000),当我做到这一点的要求是不会通过代理。

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.

我已经inlcuded了proxyObject.BypassProxyOnLocal =假。这应该使其工作没有?任何建议重新如何强制请求要经过WebProxy为HTTP调用目标定位本地地址?

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();

感谢

推荐答案

我解决这个问题只需通过添加一个点为localhost,所以不是访问本地主机,我尝试访问本地主机。 (注意点在主机名的结尾)

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)

功劳是因为: 我得到这个不寻常的技巧,从这个线程<一个href="http://www.west-wind.com/weblog/posts/2009/Jan/14/Monitoring-HTTP-Output-with-Fiddler-in-NET-HTTP-Clients-and-WCF-Proxies#596591">http://www.west-wind.com/weblog/posts/2009/Jan/14/Monitoring-HTTP-Output-with-Fiddler-in-NET-HTTP-Clients-and-WCF-Proxies#596591

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

正常工作!

这篇关于为什么不会WebProxy BypassProxyOnLocal工作给我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆