-2

I have written a code to hit a particular URL and download data using a WebClient, and have set a proxy which I have purchased from MyPrivateProxies.net to this webclient with credentials and other needed parameters through which it hits the mentioned URL.

But I get this exception every time at the last line.

System.Net.WebException: Unable to connect to the remote server System.Net.Sockets.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

below is my snippet of code:

WebClient client = new WebClient();
WebProxy webProxy = new WebProxy("my_proxy_with_port");
NetworkCredential netcredit = new NetworkCredential(username, password, domain);
client.Credentials = netcredit;
webProxy.Credentials = netcredit;
webProxy.UseDefaultCredentials = false;
webProxy.BypassProxyOnLocal = false;
client.Proxy = webProxy;
client.Encoding = Encoding.UTF8;

String strURL = "url_to_be_hit";
String jsonString = client.DownloadString(strURL);

Do I need some other settings on my windows 7 system or any config changes in app.config?

Are there other configuration for a console app to use proxies?

Smittey
  • 2,410
  • 10
  • 28
  • 33
  • Either your proxy or the request URI points to an unavailable host. Try doing some research on this very common error and double-check the strings you're passing. – CodeCaster May 19 '16 at 09:48
  • I have the feeling that both `my_proxy_with_port` and `url_to_be_hit` aren't valid arguments ... – Num Lock May 19 '16 at 10:06
  • my_proxy_with_port = xxx.xxx.xxx.xxx:29842 and url_to_be_hit= https://www.bing.com/ – Rakesh Vadnere May 19 '16 at 10:08

2 Answers2

0

I think you just need to assign the proxy credentials to the WebProxy object, not to the WebClient.

I dont know myprivateproxies.net but you have to make sure that you are using a http proxy, not a socks proxy or something else.

Mr.Sheep
  • 301
  • 2
  • 15
0

got it resolved wasn't my code issue or URI points or any of my strings which I was passing...the port was not opened at my end on local system