AFNetworking GET Parameters in body

541 views Asked by At

I have the following code and I want to force the parameters to be in the body of the GET call and not part of the query string

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);

     }];

The Details parameter is a large array and I don't want them in the query string, it currently looks like this

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

There are 1 answers

3
zaph On BEST ANSWER

NSURLConnection which underlies AFHTTPRequestOperation does not allow a body in a GET request. In general GET does not allow a body even though curl does and it usually works on the server.

If you want to send a body use a POST request.