Body 中的 AFNetworking GET 参数
AFNetworking GET Parameters in body
我有以下代码,我想强制参数位于 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
NSURLConnection
是 AFHTTPRequestOperation
的基础,不允许 GET 请求中包含正文。通常 GET 不允许主体,即使 curl 允许主体并且它通常在服务器上工作。
如果您想发送正文,请使用 POST 请求。
我有以下代码,我想强制参数位于 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
NSURLConnection
是 AFHTTPRequestOperation
的基础,不允许 GET 请求中包含正文。通常 GET 不允许主体,即使 curl 允许主体并且它通常在服务器上工作。
如果您想发送正文,请使用 POST 请求。