加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何从WebRequest中删除代理,并保持DefaultWebProxy不变

发布时间:2020-12-15 04:01:42 所属栏目:百科 来源:网络整理
导读:我使用FtpWebRequest做一些FTP的东西,我需要直接连接(没有代理).但是WebRequest.DefaultWebProxy包含IE代理设置(我估计). WebRequest request = WebRequest.Create("ftp://someftpserver/");// request.Proxy is null here so setting it to null does not h
我使用FtpWebRequest做一些FTP的东西,我需要直接连接(没有代理).但是WebRequest.DefaultWebProxy包含IE代理设置(我估计).
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

我的代码是一个巨大的应用程序,我不想更改WebRequest.DefaultWebProxy,因为它是全局静态属性,它可能会对应用程序的其他部分产生不利影响.

有什么想法怎么办?

解决方法

尝试将代理设置为空的WebProxy,即:
request.Proxy = new WebProxy();

这应该创建一个空代理.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读