您应该可以使用UserGroup.GetCurrentUserInfo
. Sharepoint SOAP 文档可以在这里找到http://msdn.microsoft.com/en-us/library/websvcusergroup.usergroup.getcurrentuserinfo(v=office.14).aspx。
如果您有权访问 Sharepoint 实例,则可以在此处检查 SOAP 信封和响应:htttp://your.sharepointserver.com/_vti_bin/usergroup.asmx?op=GetCurrentUserInfo(请勿在应用程序的实际请求中使用此 URL )。
下面是一个基于 AFNetworking 和子类 AFHTTPClient 的示例实现。
// Get user info for currently signed in user
- (void)currentUserInfoWithSuccessBlock:(void(^)(SharepointCurrentUserResponse *response))successBlock
failBlock:(void(^)(NSError *error))failBlock {
NSMutableURLRequest *request = [self requestWithMethod:@"POST"
path:@"_vti_bin/UserGroup.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>"
@"<GetCurrentUserInfo xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\" />"
@"</soap:Body>"
@"</soap:Envelope>";
// Set headers
[request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"http://schemas.microsoft.com/sharepoint/soap/directory/GetCurrentUserInfo" forHTTPHeaderField:@"SOAPAction"];
// Content length
NSString *contentLength = [NSString stringWithFormat:@"%d", soapEnvelope.length];
[request setValue:contentLength forHTTPHeaderField:@"Content-Length"];
// Set body
[request setHTTPBody:[soapEnvelope dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request
success:^(AFHTTPRequestOperation *operation, id responseData) {
NSString *xmlString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"XML response : %@", xmlString);
// Parse the response
SharepointCurrentUserResponse *response = ...
successBlock(reponse);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Get user info failed with reason: %@ status code %d",
error, operation.response.statusCode);
failBlock(error);
}];
// Que operation
[self enqueueHTTPRequestOperation:operation];
}