使用HTTPClient和Sharepoint 2013 REST API获取文档

4
我是一名.NET Web应用程序的开发者。我正在尝试使用HTTPClient和Sharepoint 2013 REST API连接到Sharepoint Online Premise,以获取“文档库”中的文档。
我在浏览器中测试了以下REST服务。
   https://site_url/_vti_bin/ListData.svc/Documents

这个功能可以提供特定网站文档库中所有文档的元数据。

现在,当我尝试通过添加到服务URL的引用并使用以下代码进行编程时,

TestSiteDataContext ctx = new TestSiteDataContext(new Uri("https://site url/_vti_bin/ListData.svc"));
ctx.Credentials = new NetworkCredential("test@test.onmicrosoft.com", "test");
var data = ctx.Documents.ToList();

我遇到了以下异常: "The request was aborted: Could not create SSL/TLS secure channel." 堆栈跟踪如下:
at System.Net.HttpWebRequest.GetResponse()
   at System.Data.Services.Client.QueryResult.Execute()
   at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
   at System.Data.Services.Client.DataServiceQuery`1.Execute()
   at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SPO_AccessAWebService.Program.Main(String[] args) in Location\Program.cs:line 35
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

我已经阅读了各种关于此问题的文章/博客,但都没有找到解决方案。我看到了一些使用{{authentication method}}进行身份验证的示例。
ctx.Credentials = CredentialCache.DefaultNetworkCredentials;

这也会抛出相同的错误。

还有其他方法可以认证SharePoint 2013 REST API吗?

有人能提供一些解决此问题的见解吗?

1个回答

0

根据您报告的异常消息,似乎SSL证书对该站点无效。我经常在使用自签名证书的开发或测试环境中看到这个消息。如果您在浏览器中访问URL时需要点击警告消息,则应该能够确定证书无效。要解决此问题,您可以尝试通过http连接(如果传输安全性不是问题),获取或安装有效证书,或将当前证书导入当前用户或本地计算机的受信任根证书存储区。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接