我已经编写了一个代码来访问特定的 URL 并使用 WebClient 下载数据,并设置了一个我从 MyPrivateProxies.net 购买的代理到这个 Web 客户端,它带有凭据和其他所需的参数,通过它访问提到的 URL。
但是我每次都在最后一行得到这个异常。
System.Net.WebException: Unable to connect to the remote server System.Net.Sockets.SocketException: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应
下面是我的代码片段:
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);
我是否需要在我的 Windows 7 系统上进行一些其他设置或任何配置更改app.config
?
控制台应用程序是否有其他配置可以使用代理?