I am using AFHTTPRequestOperationManager to post some JSON to my server, my code is below.
NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAn
You need to set your request and response serializers to handle JSON using AFJSONRequestSerializer
and AFJSONResponseSerializer
before executing your request. Using an NSDictionary literal for your parameters helps code clarity as well:
AFSecurityPolicy *policy = [[AFSecurityPolicy alloc] init];
[policy setAllowInvalidCertificates:YES];
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
[operationManager setSecurityPolicy:policy];
operationManager.requestSerializer = [AFJSONRequestSerializer serializer];
operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
[operationManager POST:@"posturl here"
parameters: @{@"name": @"john",
@"email": @"xxxxx@gmail.com",
@"password: @"xxxxx",
@"type": @"1"}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", [responseObject description]);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", [error description]);
}
];
Just solve my problem, my server was not configured to accept the charset utf8 with application/json so i just removed the charset utf for ajson serializer in Afnetworking 2.0 and now it is working correclty.