将C#WebClient与代理一起使用 – 没有请求代理服务器?
发布时间:2020-12-16 06:57:43 所属栏目:百科 来源:网络整理
导读:我们有一个后台操作(Window服务),我们想通过代理服务器使用它. 基本上,我们这样做: public WebClient GetWebClient(){ var webClient = new WebClient(); webClient.proxy = new WebProxy(Configuration.ProxyHost,Configuration.ProxyPort); // add a bunc
我们有一个后台操作(Window服务),我们想通过代理服务器使用它.
基本上,我们这样做: public WebClient GetWebClient(){ var webClient = new WebClient(); webClient.proxy = new WebProxy(Configuration.ProxyHost,Configuration.ProxyPort); // add a bunch of headers to the WebClient (sessionids,etc.) return webClient; } 代理是我们使用FreeProxy自行配置的代理. 我已经在我正在测试的机器上启用了日志记录,并且可以确认在Firefox中使用它时对代理进行了请求. 代理服务器不需要身份验证,除了IP必须在我们的办公室内(从Firefox证据,我认为不是问题). 但是,在我们的后台进程中,当我使用webclient时,我似乎没有使用代理: using(var wc = GetWebClient()) using(var s = wc.OpenRead("someurl")) using(var sr = new StreamReader(s)){ return sr.ReadToEnd(); } 我没有从代理收到任何错误,但是,即使代理已经明确设置,似乎我们只是没有它. 信息似乎返回正常,而不是通过我们的代理. 使用带有WebClient的代理时,我有什么遗漏的东西吗? 编辑:更多细节.如果我们在服务器上禁用代理服务,那么我们会得到一个我们无法连接的异常.因此,似乎webclient正在尝试联系代理,但该流量实际上并未流经代理. Inner Exception: SocketException: A connection attempt failed because the connected party did not properly respond after a period of time,or established connection failed because connected host has failed to respond 解决方法
事实证明,FreeProxy不接受HTTPS流量.
我猜代理必须返回它可以路由的流量类型,如果不能,则webclient什么也不做. 切换到使用Burp套件作为我们的代理,因为它可以接受HTTPS. http://portswigger.net/burp/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |