我使用 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();
这应该创建一个空代理。
关于c# - 如何从 WebRequest 中删除代理并保持 DefaultWebProxy 不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1559863/