2013-11-01 73 views
3

我正在.NET Web應用程序中工作。我嘗試連接到Sharepoint Online Premise以通過使用HTTPClient和Sharepoint 2013來獲取「文檔庫」中的文檔REST API。使用HTTPClient和Sharepoint 2013 REST API獲取文檔

我在瀏覽器中的這個測試以下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("[email protected]", "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找到this.Bust解決找不到任何。 我能看到各種樣品THA節目藉助驗證,

ctx.Credentials = CredentialCache.DefaultNetworkCredentials; 

這也拋出了同樣的錯誤。

是否有任何其他方式來驗證SharePoint 2013 REST API?

有人可以提供一些見解來解決這個問題嗎?

回答

0

根據您報告的異常消息,看起來SSL證書對於該網站無效。我經常在使用自簽名的開發或測試環境中看到此消息。如果您在瀏覽器中訪問URL時必須單擊警告消息,則應該能夠判斷證書是否無效。要解決此問題,如果不關心傳輸安全性,獲取或安裝有效證書或將當前證書導入當前用戶或本地計算機的受信任根權限存儲區,則可嘗試通過http進行連接。

相關問題