前提:
1.如果你访问网络需要使用代理
2.如果你控制台程序使用WebClient访问或下载文件时正常,但作为Windows Service使用 WebClient 时失败。其中报错包括但不限于:操作超时(The operation has timed out) / 无法连接到远程服务器(Unable to connect to the remote server)
请尝试在代码中定义代理地址:
var client = new WebClient();
if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["WebProxyUri"]))
{
IWebProxy proxyObject = new WebProxy(System.Configuration.ConfigurationManager.AppSettings["WebProxyUri"], true, new[] { @"172.*" });
client.Proxy = proxyObject;
}
本文介绍了解决在使用WebClient时遇到的代理问题的方法。针对访问网络需要使用代理的情况,尤其是在作为WindowsService运行时发生的超时或无法连接到远程服务器等问题,提供了具体的代码示例来配置代理。

3173

被折叠的 条评论
为什么被折叠?



