2 allenli825 allenLi825 于 2016.03.25 09:00 提问

iOS POST请求体参数两个节点怎么写

图片说明
请求体参数就是这样,我用AFN试了很多次都没成功,请求参数怎么写啊

1个回答

Alex_LoveYing
Alex_LoveYing   2016.03.25 10:32
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);
 }];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!