0
votes

I had install AFNetwork 3.1 by CocoaPods. When I call the post method i hit the error as below:

Request failed: unacceptable content-type: text/plain

Here is my code to call the post method:

AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:url];

manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.securityPolicy.allowInvalidCertificates = YES; manager.requestSerializer.timeoutInterval = 60; manager.securityPolicy.validatesDomainName = NO;

[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];

[manager POST:urlStr parameters:parameters progress:nil
      success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

          NSLog(@"%@ success, responseObject: %@", url, responseObject);


      } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

          NSLog(@"%@ error: %@", url, [error localizedDescription]);

      }];

How do I resolved this issue?

1
You are expecting json, but you are getting plain text from server. In place of application/json try this: [manager.requestSerializer setValue:@"text/plain" forHTTPHeaderField:@"Accept"];Predrag Samardzic
Yes, thanks for help. I had solved the issue, please refer my reply answer.user831098

1 Answers

0
votes

Yes, server in plain text. So I need to setup the response serializer accept content type plain text.

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];