I've been getting the following error when using the GET method to retrieve a file from a server:
Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x16e81ed0 {NSDebugDescription=Invalid value around character 0.}
I've tried a number of different things and I believe it could be something to do with the JSON format on the file that I'm trying to get.
Here is the code I've been using:
_username = @"JonDoe";
NSDictionary *parameters = @{ @"username" : _username};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
[manager GET:@"http://.........."
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
My POST method works fine. I just can't seem to fix this issue with the GET. Any ideas? Thank you.
_username
. the docs also say that the failure block is executed when the response cannot be parsed, so check the reply as well. – Assistoperation.response
? – AssistAFJSONResponseSerializer
) – Assist