I need to programmatically download a file from a SharePoint server.
When I download the file with Firefox it looks like a single request, but Httpfox shows that the HTTPS conversation is actually 4 requests:
REQ1: GET https://mycorp.raxsp.com/_windows/default.aspx?ReturnUrl=/personal/mycorp_user1/_vti_bin/cmis/rest?getRepositories
RESP1: 401 Unauthorized, WWW-Authenticate NTLM
REQ2: Authorization NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
RESP2: 401, WWW-Authenticate NTLM TlRMTVNTUAACAAAACgAKADgAAAAFgokC+[...]
REQ3: Authorization NTLM TlRMTVNTUAADAAAAGAAYAIAAAAAYA[...]
RESP3: 302 Found, Set-Cookie FedAuth=77u/PD94bW[...], Location /personal/mycorp_user1/_vti_bin/cmis/rest?getRepositories
REQ4: GET /personal/mycorp_user1/_vti_bin/cmis/rest?getRepositories
RESP4: 200 OK, <download begins>
I tried downloading the file with a simple HttpWebRequest with user/password, but as expected I just get the error 401. I am considering implementing the whole 4 requests, computing challenges with the NTLM over HTTP authentication algorithm ( spec ), but that sounds very error-prone...
Is there a client-side library or a code snippet that does NTLM over HTTP authentication?
It is for an Open Source project , so must be Open Source, and preferably using HttpWebRequest .
No Kerberos/SSO/domains involved.
We download files from SharePoint all the time with this code using System.Net.WebClient
public static byte [] downloadSharepointFile (string url){
using (var client = new WebClient { Credentials = new NetworkCredential("username", "password", "domain") })
{
client.Headers.Add("Accept: application/json");
return client.DownloadData(url);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.