简体   繁体   English

通过HTTP的NTLM:是否有C#客户端实现?

[英]NTLM over HTTP: Any C# client implementation?

I need to programmatically download a file from a SharePoint server. 我需要以编程方式从SharePoint服务器下载文件。

When I download the file with Firefox it looks like a single request, but Httpfox shows that the HTTPS conversation is actually 4 requests: 当我使用Firefox下载文件时,它看起来像是一个请求,但是Httpfox显示HTTPS对话实际上是4个请求:

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... 我尝试使用带有用户名/密码的简单HttpWebRequest下载文件,但正如预期的那样,我只收到错误401。我正在考虑实现全部4个请求,使用NTLM over HTTP身份验证算法spec )来计算挑战,但这听起来非常容易出错...

Is there a client-side library or a code snippet that does NTLM over HTTP authentication? 是否有通过HTTP身份验证进行NTLM的客户端库或代码段?
It is for an Open Source project , so must be Open Source, and preferably using HttpWebRequest . 它用于开放源代码项目 ,因此必须是开放源代码,最好使用HttpWebRequest
No Kerberos/SSO/domains involved. 不涉及Kerberos / SSO /域。

We download files from SharePoint all the time with this code using System.Net.WebClient 我们始终使用System.Net.WebClient使用此代码从SharePoint下载文件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM