I'm making a GET request for JSON using AFNetworking 2.0
self.managerMasterFetchDeletes = [AFHTTPRequestOperationManager manager];
self.managerMasterFetchDeletes.requestSerializer.timeoutInterval = 4.0f;
self.managerMasterFetchDeletes.requestSerializer = [AFJSONRequestSerializer serializer];
self.managerMasterFetchDeletes.responseSerializer = [AFJSONResponseSerializer serializer];
NSURL *URL = [NSURL URLWithString:rest];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (operation.response.statusCode==200){
NSDictionary *dictionary = (NSDictionary*)responseObject;
NSMutableDictionary *responseData = [NSMutableDictionary new];
if ([dictionary objectForKey:@"responseData"]) {
responseData = [[dictionary objectForKey:@"responseData"] mutableCopy];
}
[responseData setValue:entity forKey:@"entityName"];
[responseData setValue:[NSNumber numberWithInt:timeStamp] forKey:@"lastSync"];
[[NSNotificationCenter defaultCenter]
postNotificationName:notification
object:nil userInfo:responseData];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:[arrayOperations copy] progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
NSLog(@"%lu of %lu fetch delete complete", numberOfFinishedOperations, totalNumberOfOperations);
} completionBlock:^(NSArray *operations) {
NSLog(@"All operations in batch complete");
[[NSNotificationCenter defaultCenter]
postNotificationName:@"MasterFecthDeleteEnd"
object:nil
userInfo:nil];
}];
[self.managerMasterFetchDeletes.operationQueue addOperations:operations waitUntilFinished:NO];
But it always returns 403 with this error: unacceptable content-type: text/html
The weird thing is that the same request I do with Cocoa GraphicalHttpClient, it's ok and returns the JSON response and this:
Content-Type: application/json;charset=UTF-8 Date: Fri, 25 Sep 2015 15:28:27 GMT Transfer-Encoding: Identity X-Powered-By: Servlet/2.5 JSP/2.1
Many thanks.
AFNetworking
framework... you may need to request permission from the sysadmin for the content you want to access. – holex