1

I'm trying to do a JSON POST request (to create a new user) from my iOS app to a cloud back-end REST API using AFNetworking. In my view controller, I'm doing,

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

NSString *URLString = API_BASE_URL;
NSDictionary *parameters = @{@"userName": self.userNameTextField.text,
                             @"password": self.passwordTextField.text};

manager.requestSerializer = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:URLString parameters:parameters error:nil];

I've reviewed the docs, this SO post, and this R.Wenderlich tutorial, but my Frankenstein-ing skills are running out.

The compiler complains about

Incompatible pointer types assigning to 'AFHTTPRequestSerializer<AFURLRequestSerialization> *' from 'NSMutableURLRequest *'

Has anyone got a pointer to a working example of this or guidance on what might be wrong with my code.

Specifically, how do I initiate the action with a callback?

Community
  • 1
  • 1
mxs
  • 615
  • 6
  • 17

1 Answers1

0

Try this:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *params = @{@"userName": username, @"password": password};
manager.responseSerializer = [AFJSONResponseSerializer serializer]; // if response JSON format
[manager POST:@"http://asd.com/login.php" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@", error);
}];

Treat responseObject as NSDictionary.

Rashad
  • 11,057
  • 4
  • 45
  • 73