2010-12-06 92 views
0

任何人都可以告訴我如何調用SharePoint Web服務GetListItems。我在調用此方法如何使用目標C調用Sharepoint Web服務GetListItems C

的代碼爲我的HTTP頭請求收到錯誤消息「403禁止」是:

[theRequest setValue: cookie forHTTPHeaderField:@"Cookie"]; 
[theRequest setHTTPShouldHandleCookies:YES]; 
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue: saction forHTTPHeaderField:@"SOAPAction"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

urlconnection = [NSURLConnection connectionWithRequest:theRequest delegate:self]; 

我對調用GetListItems方法XML結構爲:

<listName>listName</listName><viewName></viewName>< Query />< ViewFields />< rowLimit>< /rowLimit>< QueryOptions>< IncludeAttachmentUrls>TRUE< /IncludeAttachmentUrls>< /QueryOptions>< webID>< /webID>< /GetListItems>< /soap:Body>< /soap:Envelope> 

有人可以告訴我我錯了什麼或者我需要做什麼嗎?

在此先感謝。

+0

嗨, 你怎麼會解決這個問題? – 2011-05-16 16:14:13

回答

0

首先你需要ASIHTTPREQUEST,它很容易使用,功能非常強大。所以,我最終會做這樣的:

NSURL *url = [NSURL URLWithString:@"http://SHAREPOINTSITE/_vti_bin/Lists.asmx"]; //Always needs to end up with _vti_bin/WHATYOUNEED.asmx 

ASIHTTPRequest *asiRequest = [ASIHTTPRequest requestWithURL:url]; 

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

[asiRequest setDelegate:self]; 

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" 
"<GetList xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">\n" 
"<listName>STRING</listName>\n" 
"</GetList>\n" 
"</soap12:Body>\n" 
"</soap12:Envelope>\n"; 

[asiRequest appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

[asiRequest addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"]; 

[asiRequest startAsynchronous]; 

下一步是設置委託:

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSString *responseString = [request responseString]; 
    NSLog(@"responseString : %@", responseString); 
    NSLog(@"Response Header: %@",[request responseHeaders]); 

    NSData *responseData = [request responseData]; 

    NSLog(@"responseData : %@", responseData); 
} 

- (void) requestFailed:(ASIHTTPRequest *)request 
{ 
    NSError *error = [request error]; 

    NSLog(@"Connection Error:  %@", error); 
    NSLog(@"Code: %i", [error code]); 
    NSLog(@"UserInfo: %@", [error userInfo]); 
    NSLog(@"Domain: %@", [error domain]); 

    NSLog(@"HelpAnchor: %@", [error helpAnchor]); 
}