我正在使用 .NET Web 应用程序。我正在尝试连接到 Sharepoint Online Premise,以使用 HTTPClient 和 Sharepoint 2013 REST API 获取“文档库”中的文档。
我为此在浏览器中测试了以下休息服务,
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("[email protected] /cdn-cgi/l/email-protection", "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()
我经历过各种文章/博客 http://www.c-sharpcorner.com/uploadfile/anavijai/rest-api-in-sharepoint-2010-for-listdata-svc-part-2/寻找解决方案。Bust找不到任何解决方案。
我可以看到各种显示通过以下方式进行身份验证的样本,
ctx.Credentials = CredentialCache.DefaultNetworkCredentials;
这也引发了同样的错误。
是否有其他方法来验证 SharePoint 2013 REST API?
有人可以为我提供一些见解来解决这个问题吗?