【发布时间】:2015-09-24 23:22:48
【问题描述】:
我正在尝试使用以下代码从 URL 下载图像:
using (System.Net.WebClient webClient = new System.Net.WebClient())
{
NetworkCredential Cred = new NetworkCredential();
Cred.UserName = "user";
Cred.Password = "password^";
webClient.Credentials = Cred;
imageBytes = webClient.DownloadData(s);
}
但是,我收到错误消息:远程服务器返回错误:(401) Unauthorized。 没有内在的例外。我正在提供我的凭据,当我将它们直接粘贴到 IE 时,我可以下载图像。 我只是无法弄清楚是什么原因造成的。
【问题讨论】:
-
天哪!非常感谢..我已经研究了这么久了。