I am working on fixing a bug in an existing project. The trouble is that AFHTTPClient is expecting a valid JSON response, but the server is returning some gibberish like ""\" Operation complete\"" (all the quotes and brackets are in the return). This causes the operation to fail, and hit the fail block, because it can't parse the response. Despite that, the server is returning status code 200, and is happy that the operation is complete.
I have a class that extends AFHTTPClient like so (exert from my .h file)
@interface AuthClient : AFHTTPClient
//blah blah blah
@end
In my implementation file the class gets initialized like so:
- (id)initWithBaseURL:(NSURL *)url{
if (self = [super initWithBaseURL:url]) {
self.parameterEncoding = AFFormURLParameterEncoding;
self.stringEncoding = NSASCIIStringEncoding;
[self setDefaultHeader:@"Accept" value:@"application/json"];
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
}
return self;
}
The call I am making is done in the class mentioned above and happens like so:
- (void)destroyToken:(NSString *)token onCompletion:(void (^)(BOOL success))completion onFailure:(void (^)(NSError *error))failure{
[self postPath:@"TheServerURL" parameters:@{@"token": token} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *error;
//Do some stuff
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//Don't want to be here.
}];
}
Inside the fail block the error is being returned in the error object's _userInfo section as:
[0] (null) @"NSDebugDescription" : @"JSON text did not start with array or object and option to allow fragments not set."
The error code is 3480.
From Googling around I gather I need to set something like NSJSONReadingAllowFragments, but I'm not sure how/where given the current setup. Does anyone have any ideas?