我正在尝试使用API调用帖子。我可以使用这个post命令,但我的问题是我有多个参数,如姓名,电话号码,电子邮件和其他多个私人信息。我尝试过这种方法,以使其工作,但没有成功。预先感谢您的任何帮助!
获取请求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
或
POST URL-Form-Encoded Request
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
答案 0 :(得分:0)
要添加更多参数,只需将它们包含在参数字典中,如下所示:
NSDictionary *parameters = @{@"foo": @"bar", @"otherFoo":@"otherBar"};
然后通过'参数'完全按照你现在的做法发布你的帖子方法。
答案 1 :(得分:0)
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar", @"key_param2":@"obj_param2", @"key_param3":@"obj_param3",@"key_paramN":@"obj_paramN"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];