Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble downloading a file
    primarykey
    data
    text
    <p>I am trying to download a file from a C# application. I have tried two different methods, but both yield the same response: "The remote server returned an error: (401) Unauthorized."</p> <p>I am pretty sure this is a credentials issue (because of the 401). If I navigate to the url from a browser, and enter the very same credentials provided, the file downloads just fine. In "Attempt 2" (below), for authtype, I have tried: NTLM, Basic, Negotiate, and Digest without any luck. </p> <p>Does anyone see what I might be doing wrong here?</p> <p>Thanks for the help!</p> <p>Attempt 1:</p> <pre><code>string username = "username"; string password = "password"; string domain = "domain"; string url = @"http://LiveLinkInstance.com/livelink/llisapi.dll/999999/WordDocument.docx?func=doc.Fetch&amp;nodeid=999999&amp;ReadOnly=True&amp;VerNum=-2&amp;nexturl=/livelink/llisapi.dll?func=ll&amp;objId=888888&amp;objAction=browse&amp;viewType=1"; // Create an instance of WebClient WebClient client = new WebClient(); client.Proxy = null; client.Credentials = new System.Net.NetworkCredential(username, password, domain); client.DownloadFile(new Uri(url), @"C:\FileDownloads\test.txt"); </code></pre> <p>Attempt 2:</p> <pre><code>string username = "username"; string password = "password"; string domain = "domain"; string url = @"http://LiveLinkInstance.com/livelink/llisapi.dll/999999/WordDocument.docx?func=doc.Fetch&amp;nodeid=999999&amp;ReadOnly=True&amp;VerNum=-2&amp;nexturl=/livelink/llisapi.dll?func=ll&amp;objId=888888&amp;objAction=browse&amp;viewType=1"; HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url); string credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(domain + "\\" + username + ":" + password)); wr.Headers.Add("Authorization", "Basic " + credentials); CredentialCache cc = new CredentialCache(); cc.Add(new Uri(url), "NTLM", new NetworkCredential(username, password, domain)); wr.Credentials = cc; Stream str = ws.GetResponseStream(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload