I want to do a POST request with AFNetworking which contains GET and POST parameters.
I am using this code:
NSString *urlString = [NSString stringWithFormat:@"upload_stuff.php?userGUID=%@&clientGUID=%@",
@"1234",
[[UIDevice currentDevice] identifierForVendor].UUIDString];
NSString *newUrl = @"https://sub.domain.com";
NSURL *baseURL = [NSURL URLWithString:newUrl];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[httpClient defaultValueForHeader:@"Accept"];
NSDictionary *getParams = [NSDictionary dictionaryWithObjectsAndKeys:
@"1234", @"userGUID",
[[UIDevice currentDevice] identifierForVendor].UUIDString, @"clientGUID",
nil];
NSDictionary *postParams = [NSDictionary dictionaryWithObjectsAndKeys:
[@"xyz" dataUsingEncoding:NSUTF8StringEncoding], @"FILE",
nil];
[httpClient postPath:urlString parameters:postParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error retrieving data: %@", error);
}];
Now I have two questions:
How can I use BOTH GET and POST dictionaries in the same request? For the time, I am integrating the GET dictionary into the URL and using only the POST dictionary (
[httpClient postPath:...]
)I am getting an error from the server stating that the parameter "FILE" is missing. Unfortunately I can't examine any server logs (not my server). But using a standard
NSURLConnection
I was able to send requests with theFILE
parameter to this server. So what is going wrong here?