AFNetworking GET体内参数

时间:2015-06-13 15:37:22

标签: ios web-services afnetworking-2

我有以下代码,我想强制参数在GET调用的主体中,而不是查询字符串的一部分

NSString * requestURL = [NSString stringWithFormat:kXXXBaseAPIURL,@"findfriends"];

NSString * lastCallTime = [[XXXCommon sharedInstance] lastTimestampForURL:requestURL];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

AFHTTPRequestSerializer * serializer =[AFJSONRequestSerializer serializer];
[[XXXCommon sharedInstance].currentAccount addAuthorization:serializer];

[manager setRequestSerializer:serializer];
[manager.requestSerializer setValue:lastCallTime forHTTPHeaderField:@"If-Modified-Since"];

[manager GET:requestURL parameters:@{@"Id":[XXXCommon sharedInstance].currentAccount.UserId, @"Details" : [[XXXCommon sharedInstance].contactFriends valueForKey:@"USER_KEY"]}
     success:^(AFHTTPRequestOperation *operation, id responseObject) {

         NSLog(@"%@",responseObject);


     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

         NSLog(@"Request failed with error: %@, %@ ", error, error.userInfo);

     }];

Details参数是一个大数组,我不希望它们出现在查询字符串中,它目前看起来像这样

http://xxx/api/findfriends?Details[]=%2B4823483943&Details[]=%2B234098234234&Details[]=%2B99999&Details[]=%2B77777777&Details[]=%2B999884&Details[]=%2B393949944

1 个答案:

答案 0 :(得分:2)

作为NSURLConnection基础的

AFHTTPRequestOperation不允许GET请求中的正文。一般来说,GET不允许身体,即使curl也是如此,它通常可以在服务器上运行。

如果您想发送正文,请使用POST请求。