在和服务端交互的过程中,一般默认的是用form-data的方式,但是在我们的项目中,要求用传json
AFHTTPSessionManager *manager=(AFHTTPSessionManager*)self.manager;
NSString *host = nil;
[manager.requestSerializer setValue:host forHTTPHeaderField:@"host"];
//默认请求头体为form-data 修改为json 上传
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
return [manager POST:URLString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
success(task, responseObject);
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
failure(task, error);
}];