首先抱怨下,这个问题搞的我焦头烂额,搞了一天,从各种百度,从刚开始的传输cookie,再到后来的POST json。以为AFN可以很好的解决这些问题,其实大家错误的利用了
[session POST:URL parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:URL parameters:dic error:nil];
[NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue]
completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error){
if (error) {
NSLog(@"Httperror: %@%ld", error.localizedDescription, error.code);
} else {
NSJSONSerialization *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSDictionary *dicjson = (NSDictionary *)json;
NSLog(@"%@",dicjson);
}
}];
希望对有同样错误的TX有所帮助。