HttpWebRequest一个代理,一个不 [英] HttpWebRequest one proxy and one not

查看:60
本文介绍了HttpWebRequest一个代理,一个不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何代理我的连接?我想要3个默认的HttpWebRequest objs,它将不会通过代理,而另外3个会.我是否做WebRequestObject.Proxy = myProxy;在我想使用代理的对象上,对3个我不做的对象不做任何事情?对象也将以未知顺序进行初始化,因此我可能有2个没有,有2个被代理,第3个isnt和最后一个.仅仅是写.Proxy = myProxy吗?

How do i proxy my connections? i want 3 default HttpWebRequest objs that will not go through a proxy and another 3 that does. Do i do WebRequestObject.Proxy = myProxy; on objects i want to use a proxy on and do nothing on the 3 objs i do not? also the objects will initialize in an unknown order so i may have 2 not, 2 that is proxied, a 3rd that isnt and a final that is. Is it just simply writing .Proxy = myProxy?

推荐答案

对于需要代理的请求,可以,可以很好地工作:

For requests that require a proxy, yes, that'll work fine:

request.Proxy = myProxy;

对于希望绕过代理的请求,请使用:

For requests that wish to bypass a proxy, use:

request.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy;

如果要使用IE的默认代理(或者如果您在app/web.config中设置了默认代理),则只需不设置代理或将其设置为null:

If you want to use the IE's default proxy (or if you've set a default proxy in your app/web.config), simply don't set the proxy, or set it to null:

request.Proxy = null;

有关可能的HttpWebRequest.Proxy值在这里和此处为GetEmptyWebProxy .

这篇关于HttpWebRequest一个代理,一个不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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