我从服务器获取数据。服务器端是从客户端维护。我只是解析数据并使用AFNetworking。但可能是某些SOAPACtion有错误。服务器无法识别HTTP标头SOAPAction的值:http://test.server.com/Role
HTTP POST:
POST /service/services.asmx/Role HTTP/1.1
Host: server.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length
SyncResetData=string
代码:
NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">\n"
"<soap:Body>\n"
"<Sync_Reset_Role xmlns=\"http://test.server.com/\">\n"
"<SyncResetData><![CDATA[%@]]></SyncResetData>\n"
"</Sync_Reset_Role>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",string];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/services.asmx?wsdl/Role",SERVICE_ENDPOINT]];
NSLog(@"url is getResetRoleContentLength %@",url);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *strLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue: [NSString stringWithFormat:@"http://test.server.com/Role"] forHTTPHeaderField:@"SOAPAction"];
[request addValue: strLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *operation2 = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation2 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation2, id responseObject2) {
} failure:^(AFHTTPRequestOperation *operation2, NSError *error) {
NSLog(@"Error: %@", error);
if([delegate respondsToSelector:@selector(requestFailed)]){
[delegate performSelector:@selector(requestFailed)];
}
}];
错误:
Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 500" UserInfo=0x6995430 {NSLocalizedRecoverySuggestion=<?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><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://test.server.com/Role.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x693c870>, NSErrorFailingURLKey=http://test.server.com/test/services.asmx?wsdl/Role, NSLocalizedDescription=Expected status code in (200-299), got 500, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://test.server.com/test/services.asmx?wsdl/Role>}