**************EDITED*******************
I am relatively new to iOS and I want to make a post request using the following code:
I am getting a NSLocalizedDescription=Request failed: unacceptable content-type: text/html, NSErrorFailingURLKey=https://xxxxxx-xxxxxx/xxxx/xxxx}}, com.alamofire.serialization.response.error.response= { URL: https://xxxxxx/xxx/xxxx/xxxxxs }
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
[requestSerializer setValue:token1 forHTTPHeaderField:@"Authorization"];
[requestSerializer setValue:@"PP" forHTTPHeaderField:@"x-service-code"];
[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager setRequestSerializer:requestSerializer];
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:
token.tokenId, @"payment_method_nonce",
details.city, @"city",
details.address1, @"address1",
details.state, @"state",
details.zipcode, @"zip",
nil];
[manager POST:url parameters:params
success:^(NSURLSessionDataTask *task, id responseObject)
{
NSLog(@"SUCCEEDED");
}
failure:^(NSURLSessionDataTask *task, NSError *error)
{
loadingOverlay.hidden = YES;
NSLog(@"FAILED %@",error);
}];
I have found out what the issue is: I need to send params as raw JSON and it's not doing that. How do I achieve this?
I want params to go in raw format i.e.
{"payment_method_nonce":"tok_xxxxxxxx"}
Solved it I used a NSMutableDictionary instead:
and used AFHTTPRequestOperationManager instead of AFHTTPSessionManager