Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove proxy from WebRequest and leave DefaultWebProxy untouched

Tags:

c#

.net

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

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.

Any idea how to do it?

like image 713
Elephantik Avatar asked Oct 13 '09 12:10

Elephantik


1 Answers

try setting the proxy to an empty WebProxy, ie:

request.Proxy = new WebProxy();

This should create an empty proxy.

like image 108
Alastair Pitts Avatar answered Sep 21 '22 15:09

Alastair Pitts