【问题标题】:Using the HTTPClient and Sharepoint 2013 REST APIs to get Documents使用 HTTPClient 和 Sharepoint 2013 REST API 获取文档
【发布时间】:2013-11-05 11:25:32
【问题描述】:

我正在使用 .NET Web 应用程序。我正在尝试使用 HTTPClient 和 Sharepoint 2013 REST API 连接到 Sharepoint Online Premise 以获取“文档库”中的文档。

为此,我在浏览器中测试了以下休息服务,

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

我收到以下异常: “请求被中止:无法创建 SSL/TLS 安全通道。” 堆栈跟踪如下:

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()

我已经通过各种articles/blogs 寻找解决方案。Bust 找不到任何解决方案。 我可以看到通过 , 进行身份验证的各种样本,

ctx.Credentials = CredentialCache.DefaultNetworkCredentials;

这也抛出了同样的错误。

还有其他方法可以对 SharePoint 2013 REST API 进行身份验证吗?

有人可以提供一些见解来解决这个问题吗?

【问题讨论】:

    标签: asp.net rest sharepoint sharepoint-2013


    【解决方案1】:

    根据您报告的异常消息,SSL 证书似乎对该站点无效。我经常在使用自签名美分的开发或测试环境中看到此消息。如果在浏览器中访问 URL 时必须单击警告消息,您应该能够判断证书是否无效。要解决此问题,如果不考虑传输安全性,您可以尝试通过 http 连接,获取或安装有效证书,或将当前证书导入当前用户或本地计算机的 Trusted Root Authorities 存储。

    【讨论】:

      猜你喜欢
      • 2015-11-30
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多