开发者

how to call the sharepoint web service GetListItems using objective C

Can any one tell me how to call the SharePoint web service GetListItems. I am getting an error message "403 Forbidden" on calling this method

The code for my HTTP header request is:

[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 c开发者_如何学运维onnectionWithRequest:theRequest delegate:self];

My XML structure for calling the GetListItems methods is:

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

Can anybody tell me where I am wrong or what else I need to do?

Thanks in advance.


First of all you need ASIHTTPREQUEST, it's easy to use and very powerful. So I end up doing it like this:

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];

Next step is to set the delegate:

- (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]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜