简体   繁体   中英

AFNetworking GET Parameters in body

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM