2

我需要以编程方式从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 身份验证算法规范)计算挑战,但这听起来很容易出错...

是否有客户端库或代码片段执行 NTLM over HTTP 身份验证?
它是针对开源项目的,所以必须是开源的,最好使用HttpWebRequest
不涉及 Kerberos/SSO/域。

4

1 回答 1

1

我们一直使用此代码从 SharePoint 下载文件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);
          }
}
于 2015-09-03T19:57:34.983 回答