2012-12-18 39 views
3

我正在開發iOS iPad應用程序以連接到Sharepoint。我正在用ASIHTTPRequest框架來做這件事。我的代碼看起來像這樣:iOS Sharepoint App登錄錯誤

NSURL *url = [NSURL URLWithString:@"https://SHAREPOINTURL"]; 

NSString *soapMessage = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n" 
"<soap12:Body>\n" 
"<GetListCollection xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\" />\n" 
"</soap12:Body>\n" 
"</soap12:Envelope>\n"; 

asiRequest = [ASIHTTPRequest requestWithURL:url]; 

[asiRequest setUsername:@"USERNAME"]; 
[asiRequest setPassword:@"PASSWORD"]; 

[asiRequest setDelegate:self]; 
[asiRequest appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 
[asiRequest addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"]; 
[asiRequest startAsynchronous]; 

到目前爲止,這麼好,但是當我調試這個,我得到一個403 FORBIDDEN錯誤。爲什麼? 在我看來,我不認爲這些錯誤是用戶名和密碼。請求可能有問題嗎?

回答

0

既然你沒有發佈你的網址,我不得不問,你是在_vti_bin/authentication.asmx

如果你已經是我只能建議這個,因爲我不知道ASI是否正確地登錄信息。嘗試將它放在你的SOAP消息手動像這樣:(從here

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
    <Login xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
     <username>USERNAME</username> 
     <password>PASSWORD</password> 
    </Login> 
    </soap:Body> 
</soap:Envelope> 

這應返回你需要使用的網絡服務,其餘的登錄cookie。

編輯:還有一件事,你需要設置你的SP服務器使用表單身份驗證,而不是NTLM身份驗證(這是默認值)。

+0

嗯..一定有一個錯誤。唯一的想法是服務器返回idt this:<?xml version =「1.0」encoding =「utf-8」?> soap:客戶端無法無需有效的操作參數即可處理請求。請提供有效的肥皂動作。 user1913839

0

看着你的SOAP信封和錯誤信息,我認爲你在請求中缺少SOAPAction標題。

下面的代碼顯示瞭如何創建獲取Sharepoint實例中所有列表的請求的示例。我正在使用AFNetworking,有些部分可能不適用於ASIHTTPRequest框架。

... 

NSMutableURLRequest *request = [self requestWithMethod:@"POST" 
                path:@"_vti_bin/Lists.asmx" 
              parameters:nil]; 

NSString *soapEnvelope = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
    @"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" 
    @"<soap:Body>" 
    @"<GetListCollection xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\" />" 
    @"</soap:Body>" 
    @"</soap:Envelope>"; 

// Set headers 
[request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[request setValue:@"http://schemas.microsoft.com/sharepoint/soap/GetListCollection" forHTTPHeaderField:@"SOAPAction"]; 

// Content length 
NSString *contentLength = [NSString stringWithFormat:@"%d", soapEnvelope.length]; 
[request setValue:contentLength forHTTPHeaderField:@"Content-Length"]; 

// Set body 
[request setHTTPBody:[soapEnvelope dataUsingEncoding:NSUTF8StringEncoding]]; 

... 

但是,正如蒂姆所說,在使用這種方法之前,您必須進行身份驗證。

有幾種認證機制,Tim或NTLM(以及其他)描述的上述Forms聲明。您必須檢查Sharepoint實例的配置方式,或者如果您無法控制服務器的配置,則可能支持多種機制。