标签:afn style init progress erro http 使用 man serialize
设置请求头:[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
GET方法设置请求头的时候没什么问题;
但是使用POST方法时设置无效,使用其他方法都没用,后来发现没有序列化
manager.requestSerializer = [AFJSONRequestSerializer serializer];
注意: 和manager.requestSerializer = [AFHTTPRequestSerializer serializer];不一样
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [manager POST:url parameters:parametersDictionary progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"success!"); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"error: %@", error); }];
参考:
https://www.jianshu.com/p/cd53b108dd42
https://www.jianshu.com/p/625924f6f052
标签:afn style init progress erro http 使用 man serialize
原文地址:https://www.cnblogs.com/lulushen/p/9762025.html