2011-09-06 48 views
3

我開始知道我們可以使用REST apis從SharePoint網站獲取數據。此外SharePoint還支持從2010年起的REST。我獲得了用於列出SharePoint中的數據及其詳細信息的API。它是「ListData.svc」。是否還有其他類似於我們可以驗證我們網站的API。我嘗試了它瀏覽器(listdata.svc),並在此之前,我登錄。如果我註銷並執行「siteUrl/_vti_bin/ListData.svc」,我無法得到結果,請求超時或有時它顯示網頁不可用。如果有人知道如何在iPhone應用程序的SharePoint的東西,請分享一些相同的東西。如何使用來自iOS應用程序的REST API對Microsoft SharePoint網站進行身份驗證

回答

2

閱讀原文:http://sharepointsemantics.com/2011/07/the-client-side-object-model-help-with-headless-authentication-in-sharepoint-online/請確保您閱讀了由Chris Johnson撰寫的鏈接文章,然後提供信息以解決您的身份驗證問題。

旁註,你幾乎必須在SharePoint端使用表單身份驗證。

+1

我得到了這個答案,我以前的問題之一。這不是我問的那個。我需要關於REST API。它講述了CSOM,這是另一種數據訪問方法。 –

+1

相同的技術可以用於REST調用。您將取回相同的Cookie並將它們附加到REST HTTP呼叫。我的博客帖子中的幫手代碼將幫助您獲取這些Cookie。 –

2

以下是我通過http爲SharePoint 2010進行NTLM身份驗證的方式。它可以工作並返回任何來自listdata.svc的調用的JSON字典(例如,調用URL yourdomain/_vti_bin/listdata.svc/YourList):

抓取AFNetworking並按照說明進入XCode應用程序。

當您的項目中有AFNetworking編譯時,您需要繼承AFNetworking框架的AFHTTPClient類。例如。添加一個新的類到你的iOS XCode項目並選擇AFHTTPClient作爲它的對象類型。

一旦你的子類你喜歡的東西如下:

YourHTTPClient.h

#import "AFHTTPClient.h" 
#import "AFJSONRequestOperation.h" 
#import "AFNetworkActivityIndicatorManager.h" 

typedef void(^OLClientSuccess) (AFJSONRequestOperation *operation, id responseObject); 
typedef void(^OLClientFailure) (AFJSONRequestOperation *operation, NSError *error); 

@interface OLHTTPClient : AFHTTPClient 
{ 

NSString *strBASEURL; 
NSString *strUser; 
NSString *strPassword; 

} 

@property (nonatomic, retain) NSString *strUser; 
@property (nonatomic, retain) NSString *strPassword; 
@property (nonatomic, retain) NSString *strBASEURL; 

+(id) sharedClient; 

- (void)setUsername:(NSString *)username andPassword:(NSString *)password; 

-(void) getStuff:(OLClientSuccess) success failure:(OLClientFailure) failure; 

@end 

將在YourHTTPClient.m文件,你可以有下面的代碼,但在這個.m文件就是您將實現自定義方法調用以從SharePoint獲取您的列表數據。請看下圖:

進行身份驗證的代碼片段從YourHTTPClient.m:

- (void)getPath:(NSString *)path parameters:(NSDictionary *)parameters 
    success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 
    failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure 
{ 
NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:parameters]; 
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure]; 
[operation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) { 
    NSURLCredential *newCredential = [NSURLCredential credentialWithUser:self.User password:self.password persistence:NSURLCredentialPersistenceForSession]; 
    [challenge.sender useCredential:newCredential forAuthenticationChallenge:challenge]; 
}]; 
[self enqueueHTTPRequestOperation:operation]; 
} 

@end 

我只是試圖與配置爲使用NTLM身份驗證在SharePoint 2010環境上面。如果您需要使用Kerberos進行身份驗證,則可能需要重新配置,但我懷疑它也可能使用AFNetworking。

0

看看這個項目,它支持SharePoint 2013 RestAPI.Its爲我工作,並非常確定它也適用於你。

https://github.com/jimmywim/SPRestAPI 

默認情況下,SPRESTQuery提供XML格式的響應,如果你想在JSON響應,你將不得不寫在executeQuery方法這一行。

[apiRequest setValue:@"application/json;odata=verbose" forHTTPHeaderField:@"Accept"]; 
相關問題