我需要以编程方式从SharePoint服务器下载文件。

当我使用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>


我尝试使用带有用户名/密码的简单HttpWebRequest下载文件,但正如预期的那样,我只收到错误401。我正在考虑实现全部4个请求,并使用NTLM over HTTP authentication algorithmspec)计算挑战,但是听起来很容易出错...

是否有通过HTTP身份验证进行NTLM的客户端库或代码段?
它用于an Open Source project,因此必须是“开源”,最好使用HttpWebRequest
不涉及Kerberos / SSO /域。

最佳答案

我们始终使用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);
          }
}

关于c# - 通过HTTP的NTLM:是否有C#客户端实现?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15802272/

10-13 08:37