This question already has an answer here:

I am working on an iOS app, using web-service. For call my web-service i decided to use AFNetWorking 2.0. And i have a big issue : On the command line i use curl :

    curl -X POST -d '[{"username":"user123","password":"querty"}]' -H "Content-Type:          application/json" http://mysite

This works perfectly.

Now when i want to use on iOS App:

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];

    [manager.requestSerializer setValue:@"application/json; text/html" forHTTPHeaderField:@"Accept"];
    [manager.requestSerializer setValue:@"application/json; text/html; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    NSDictionary *parameters = @{@"username": @"user123", @"password":@"querty"};

    [manager POST:@"http://mysite" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);

i got this error : Request failed: unacceptable content-type: text/html

Related posts

Recent Viewed