NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", WebURL]]];
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[request setTimeoutInterval: 30];
NSString*msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[request addValue: @"text/xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];
[request addValue:@"IOS App (power by elliott)" forHTTPHeaderField:@"User-Agent"];
[request addValue:soapActionURL forHTTPHeaderField:@"SOAPAction"];
[request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
// Make sure to set the responseSerializer correctly
//operation.responseSerializer = [AFXMLParserResponseSerializer serializer];
//
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)operation.response;
if (httpResponse.statusCode == 200) {
dispatch_async(dispatch_get_main_queue(), ^{
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:responseObject];
//[xmlParser setShouldProcessNamespaces:NO];
//[xmlParser setShouldReportNamespacePrefixes:NO];
//[xmlParser setShouldResolveExternalEntities:NO];
[xmlParser setDelegate:myhttp];
[xmlParser parse];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
});
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
DLog(@"errror: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{
if (_delegate && [_delegate respondsToSelector:@selector(updateVCwithNetError: method:)]) {
[_delegate updateVCwithNetError:@"请求出错" method:myhttp.soapMethod];
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
});
}];