After AFNetworking was upgraded to 3.0, many interfaces were unavailable. The original way of sending SOAP to WebService had to be changed, and there was very little information on the web.
This is how I do it.
NSString *soapMessage =[NSString stringWithFormat (soap string)];
NSString *soapLength = [NSString stringWithFormat:@”%lu”, (unsigned long)[soapMessage length]];
// Server address
NSString *Url =[NSString stringWithFormat :(IP string)];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes
setByAddingObject:@”text/xml”];
[manager.requestSerializer setValue:@”application/soap; charset=utf-8″ forHTTPHeaderField:@”Content-Type”];
[manager.requestSerializer setValue:soapLength forHTTPHeaderField:@”Content-Length”];
// Set the timeout period
[manager.requestSerializer willChangeValueForKey:@”timeoutInterval”];
Manager. RequestSerializer. TimeoutInterval = 10.0 f;
[manager.requestSerializer didChangeValueForKey:@”timeoutInterval”];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@”POST” URLString:Url parameters:nil error:nil];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:
^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if(! error)
{
// Successful processing
}
else
{
// Error handling
}
}];
[task resume];
});
I CSDN blog at http://write.blog.csdn.net/postedit/53217316.