vishal vishal - 6 months ago 32
iOS Question

Posting JSON data using AFNetworking 2.0

I have a web script which accepts JSON string as input through HTTP POST request.
I have came across several AFNetworking 1.x example for the same , can anybody please point me or give AFNetworking 2.0 example to do an HTTP POST request to a web script with formatted JSON as input ?



after searching docs and trying out some codes I got following as an example

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];

NSDictionary *params = @ {@"user" :txtUserName, @"pwd" :txtPwd };

[manager POST:URL_SIGNIN parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject)
    NSLog(@"JSON: %@", responseObject);
 ^(AFHTTPRequestOperation *operation, NSError *error) {
     NSLog(@"Error: %@", error);

Also don't forget to set response header type in the server script as Application/json.