[英]Webclient causing an invalid operation exception
我正在尝试下载一个简单的xml文件并将其保存到用户本地配置文件。 尝试下载时(我不认为这与保存位置有关,但我不是100%肯定),我在webclient上收到以下异常。
System.InvalidOperationException
我的代码如下:
public void downloadProxy() {
string url = Properties.Settings.Default.url;
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "/netsettings/proxies.xml");
try
{
WebClient GrabFile = new WebClient();
GrabFile.DownloadFile(url, path);
}
catch (WebException webEx)
{
if (webEx.Status == WebExceptionStatus.ConnectFailure)
{
Console.WriteLine("Are you behind a firewall? If so, go through the proxy server.");
}
}
}
如果您使用的是Windows操作系统,请使用反斜杠(而不是斜杠)作为文件夹分隔符:
\netsettings\proxies.xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.