0

I am trying to download an image from a URL using the following code:

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);
}

However, I get the error : The remote server returned an error: (401) Unauthorized. There is no inner exception. I am giving my crendentials, and I am able to download the image when I paste them directly to IE. I am just not able to figure out what is causing this.

Rahul Kishore
  • 380
  • 1
  • 8
  • 19
perplexedDev
  • 857
  • 4
  • 17
  • 49

1 Answers1

0

Setting webClient.UseDefaultCredentials = true; solved my issue

perplexedDev
  • 857
  • 4
  • 17
  • 49