2010-12-06 75 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]); 
}