POST /WebService.asmx HTTP/1.1 Host: 139.196.32.138 Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <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"> <soap12:Body> <TransformData xmlns="http://tempuri.org/"> <str_json>string</str_json> </TransformData> </soap12:Body> </soap12:Envelope>解析代码如下:
//------ 拼接SOAP协议 ------
NSDictionary *dataDictionary = [NSDictionarydictionaryWithObjectsAndKeys:
@"888888",@"TaskGuid",
@"888888",@"DataType",
@"888888",@"LoginAccount",
@"888888",@"Password",nil];
NSError *error =nil;
NSData *jsonData = [NSJSONSerializationdataWithJSONObject:dataDictionary
options:NSJSONWritingPrettyPrinted
error:&error];
NSString *jsonString = [[NSStringalloc]initWithData:jsonData
encoding:NSUTF8StringEncoding];
NSString *soapMessage = [NSStringstringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<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\">"
"<soap12:Body>"
"<TransformData xmlns=\"http://tempuri.org/\">"
"<str_json>%@</str_json>"
"</TransformData>"
"</soap12:Body>"
"</soap12:Envelope>",jsonString];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
manager.responseSerializer = [[AFHTTPResponseSerializeralloc]init];
[manager.requestSerializersetValue:@"139.196.32.138"forHTTPHeaderField:@"Host"];
[manager.requestSerializersetValue:@"application/soap+xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializersetValue:[NSStringstringWithFormat:@"%d",(int)soapMessage.length]forHTTPHeaderField:@"Content-Length"];
NSMutableURLRequest *request = [manager.requestSerializerrequestWithMethod:@"POST"URLString:@"http://139.196.32.138:10011/WebService.asmx?op=TransformData"parameters:nilerror:nil];
[request setHTTPBody:[soapMessagedataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *operation = [managerHTTPRequestOperationWithRequest:requestsuccess:^(AFHTTPRequestOperation *operation,id responseObject) {
NSString *xmlString = [[NSStringalloc]initWithData:(NSData *)[operationresponseObject]encoding:NSUTF8StringEncoding];
//使用NSData对象初始化
GDataXMLDocument *xmlDoc = [[GDataXMLDocumentalloc]initWithXMLString:xmlStringoptions:0error:nil];
//获取根节点
GDataXMLElement *xmlEle = [xmlDocrootElement];
NSArray *array = [xmlElechildren];
for (int i =0; i < [arraycount]; i++) {
GDataXMLElement *ele = [arrayobjectAtIndex:i];
NSLog(@"%@",[elestringValue]);
[ele stringValue]是解析结果,可以进一步转换成json对象
}
} failure:^(AFHTTPRequestOperation *operation,NSError *error) {
NSLog(@"===%@",error);
}];
[manager.operationQueueaddOperation:operation];