Can NSURLSession specify the type of data to be obtained? For example, if I want to obtain xml, but what is actually obtained is json, an error will be reported
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
[configuration setHTTPAdditionalHeaders:@{@"Accept": @"application/xml"}];
[configuration setHTTPAdditionalHeaders:@{@"Content-Type": @"application/xml"}];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSessionDataTask *task = [session dataTaskWithURL:url
completionHandler:^(NSData * _Nullable data,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
if (error) {
NSLog(@"%@", [error localizedDescription]);
} else {
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
if (200 != statusCode) {
NSLog(@"HTTP status code = %ld", statusCode);
success = NO;
}
NSLog(@"%@", data);
}
}];
NSURLSession does not have this function, you can try to use AFNetworking