如何从WebRequest的去除代理并留下DefaultWebProxy不变 [英] How to remove proxy from WebRequest and leave DefaultWebProxy untouched

查看:142
本文介绍了如何从WebRequest的去除代理并留下DefaultWebProxy不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的FtpWebRequest做一些FTP的东西,我需要直接连接(无代理)。然而WebRequest.DefaultWebProxy包含IE代理服务器设置(我认为)。

I use FtpWebRequest to do some FTP stuff and I need to connect directly (no proxy). However WebRequest.DefaultWebProxy contains IE proxy settings (I reckon).

WebRequest request = WebRequest.Create("ftp://someftpserver/");
// request.Proxy is null here so setting it to null does not have any effect
WebResponse response = request.GetResponse();
// connects using WebRequest.DefaultWebProxy

我的code是一块在一个巨大的应用程序,我不想改变 WebRequest.DefaultWebProxy ,因为它是全球性的静态属性,它可以产生不利上的应用程序的其他部分的影响。

My code is a piece in a huge application and I don't want to change WebRequest.DefaultWebProxy because it is global static property and it can have adverse impact on the other parts of the application.

任何想法怎么办呢?

推荐答案

尝试代理设置为空WebProxy,即:

try setting the proxy to an empty WebProxy, ie:

request.Proxy = new WebProxy();

这应该创建一个空的代理服务器。

This should create an empty proxy.

这篇关于如何从WebRequest的去除代理并留下DefaultWebProxy不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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