C# 401尝试下载图像时发生未经授权的错误
我正在尝试使用以下代码从URL下载图像:C# 401尝试下载图像时发生未经授权的错误,c#,.net,webclient,C#,.net,Webclient,我正在尝试使用以下代码从URL下载图像: using (System.Net.WebClient webClient = new System.Net.WebClient()) { NetworkCredential Cred = new NetworkCredential(); Cred.UserName = "user"; Cred.Password = "password^"; webClient.Credentials = Cred; image
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。
内部没有例外。我给我的crendentials,我可以下载图像时,我把他们直接粘贴到IE。
我只是无法找出造成这种情况的原因。设置webClient.UseDefaultCredentials=true;解决了我的问题见哦,老兄!非常感谢。。这件事我已经做了很长时间了。