问题描述
解决方案
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//申明返回的结果是json类型
manager.responseSerializer = [AFJSONResponseSerializer serializer];
//申明请求的数据是json类型
manager.requestSerializer = [AFJSONRequestSerializer serializer];
//下列请求头参数根据你自己的后台接口要求来设置
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"keep-alive" forHTTPHeaderField:@"Connection"];
[manager.requestSerializer setValue:@"zh-cn" forHTTPHeaderField:@"language"];
//如果报接受类型不一致请替换一致text/html或别的
manager.responseSerializer.acceptableContentTypes = nil;
//传入的参数
NSDictionary *parameters = @{@"pageNo" : pageNo,
@"userId" : userId,
@"pageSize" : pageSize
};
//你的接口地址
NSString *urlString = @"https://.....";
//发送请求
[manager POST:urlString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"请求成功");
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"[HTTPClient Error]: %@", error);
}];
时间: 2024-12-30 20:26:13