iosobjective-cafnetworking

Wrong response parsing in AFNetworking


AFNetworking receives right response, but parsing returns error. I understand, that I set wrong setting in manager, but can't understand, which will be right.

My code:

manager = [[AFHTTPSessionManager alloc] initWithBaseURL:kAuthorizationUrl];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/x-plist",nil];
[manager POST:@"someURL" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject){
    NSLog(@"");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    NSLog(@"");
}];

returning error:

"No value for key in object around character 35."

Response body from postman:

{
"featureAppleTVSynchronisation" = "false";
"featureDirectPlay" = "true";
"googleLoginSwitchOn" = "true";
}

Response headers:

Accept-Ranges →bytes
Access-Control-Allow-Credentials →true
Access-Control-Allow-Methods →GET, POST, OPTIONS
Connection →keep-alive
Content-Encoding →gzip
Content-Type →application/x-plist; charset=UTF-8
Date →Tue, 18 Oct 2016 19:57:05 GMT
Server →Apache/2.4.6 (CentOS)
Transfer-Encoding →chunked
Vary →Accept-Encoding
X-Varnish-Retries →0
cache-control →private, no-cache, no-store, must-revalidate, max-age=0
expires →Tue, 18-Oct-2016 19:00:28 GMT

Solution

  • Ok, I found solution: Right code

    manager = [[AFHTTPSessionManager alloc] initWithBaseURL:kAuthorizationUrl];
    // Attention please! Here is what I changed!
    manager.responseSerializer = [AFPropertyListResponseSerializer serializer];
    // End
    [manager POST:@"someURL" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject){
        NSLog(@"");
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"");
    }];