Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking - How to specify multiple values for one key

Tags:

afnetworking

I am trying to pass multiple values for one parameter key to an HTTP request using the AFHTTPClient method "postPath". However, the parameters variable is an NSDictionary so I can not set multiple values for my key "email". I've tried sending the e-mail values as a comma separated string but that does not work as my server returns an error saying I have not specified any e-mail value.

I did read in the documentation about using multipartFormRequestWithMethod method but I could not completely figure out how to make this work. Can anyone provide an example of using this method with multiple values for a single key?

Thanks

Rich

like image 507
Rich Morey Avatar asked Jun 18 '12 17:06

Rich Morey


1 Answers

Combining the multi query values for one key.

If you use NSDictionary + NSSet you get query url without [] from NSArray.

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
[NSSet setWithObjects:@"value1", @"value2", nil], @"myKey", nil];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSURLRequest *request = [httpClient requestWithMethod:@"GET" path:@"/path" parameters:params];

PS: Better late than never...

like image 169
Mitja Gomboc Avatar answered Sep 26 '22 14:09

Mitja Gomboc