gowalla/AFNetworking — Issue #74: JSON POST REQUEST
Author: satbam
Created: 2011-10-14 02:10:51+00:00
State: open

Hi There, I am very new to obj-c and looking to understand what I am doing wrong here. I am sending a JSON Request to the Server
-> If I do a GET it works
-> When I do a post with parameters I get the error invalid form data in IOS 5, in 4.3 i had no issues.

here is my code

NSURL *url = [NSURL URLWithString:@"http://mysite.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
usernamestring, @"login[username]",
emailstring, @"login[email]",
nil];

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path: nil parameters:parameters];
// ------------I think the issue is here with my parameters they seem not to being passed--------//

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

NSLog(@"%@",request);
NSString *status = [JSON valueForKey:@"status"];
NSLog(@"%@",status);
if ([status isEqualToString:@"success"]) {
[username resignFirstResponder];
[password resignFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}
else {
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Login Unsuccessful"
message:@"Try again"
delegate:NULL
cancelButtonTitle:@"OK"
otherButtonTitles:NULL];

[alert show];
}

}
failure:nil];

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
NSLog(@"check");