title: WebClient DownloadFile with Authorization not working
body: <p>I have tried just about everything I can think of to get this to work, including several things I've found online. All I'm trying to do is download a file (which has a direct link) from a website that I have to log in to.</p>
  <p>I tried doing the following, with the &quot;UploadValues&quot;:</p>
  <pre><code>WebClient myWebClient = new WebClient();
  NameValueCollection myNameValueCollection = new NameValueCollection();
  myNameValueCollection.Add(&quot;username&quot;, this.UserName);
  myNameValueCollection.Add(&quot;password&quot;, this.Password);
  byte[] responseArray = myWebClient.UploadValues(felony, myNameValueCollection);
  myWebClient.DownloadFile(felony, localfelony);
  </code></pre>
  <p>and I've also tried putting the login info in the headers as well.  I've also tried just setting the credentials, as you can see from the commented code:</p>
  <pre><code>WebClient client = new WebClient();
  //client.UseDefaultCredentials = false;
  //client.Credentials = new NetworkCredential(this.UserName, this.Password);
  client.Headers.Add(HttpRequestHeader.Authorization, &quot;Basic &quot; + Convert.ToBase64String(Encoding.ASCII.GetBytes(this.UserName + &quot;:&quot; + this.Password)));
  client.Headers.Add(HttpRequestHeader.UserAgent, &quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36&quot;);
  //client.Headers.Add(HttpRequestHeader.Cookie, this.webBrowser.Document.Cookie);
  client.DownloadFile(felony, localfelony);
  </code></pre>
  <p>No matter what I try, the only thing I can get it to download is a file that ends up being the login page, as if it didn't accept the login info I passed.</p>
  <p>I've looked at the headers and such, and I don't see anything out of the ordinary that would explain why this isn't working. Any ideas?</p>