AFNetworking - How to specify multiple values ​​for a single key

I am trying to pass multiple values ​​for a single parameter key to an HTTP request using the AFHTTPClient "postPath" method. However, the parameter variable is NSDictionary, so I cannot set multiple values ​​for my "email". I tried sending the email values ​​as a comma-separated string, but this does not work as my server returns an error stating that I did not specify any email value.

I read in the documentation about using the multipartFormRequestWithMethod method, but I could not fully understand how to do this. Can someone provide an example of using this method with multiple values ​​for a single key?

thank

Rich

+5
source share
3 answers

Combining the values ​​of multiple queries for a single key.

If you use NSDictionary + NSSet, you get a url request 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 ...

+12
source

Combining multiple values ​​for one key.

using NSDictionary + NSArray

For instance:

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"param1", @"value2", @"param2", [NSArray arrayWithObjects:@"value3",@"value4",@"value5",nil], @"param3", nil];

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/yourhostpath" parameters:params];

you need to replace "url" and "yourhostpath" with your own, please refer to the AFHttpClient demo code for AFNetworking for this.

+4
source

. , , .

, , email , . , , , emails.

+2

All Articles