AFNetWorking实现参数以body传输请求数据
/** * 异步POST请求:以body方式,支持数组 * * @param url 请求的url * @param body body数据 * @param success 成功回调 * @param failure 失败回调 */ + (void)postWithUrl:(NSString *)url body:(NSData *)body success:(HttpSuccess)success failure:(HttpSuccess)failure { NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:url parameters:nil error:nil]; request.timeoutInterval = TIMEOUTINTERVAL; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; // 设置body [request setHTTPBody:body]; AFHTTPSessionManager * manager = [AFHTTPSessionManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", nil]; [[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { if (error) { failure(error); } else { id json = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil]; success(json); } }] resume]; }
思思亲测,可用哟😄