我使用AFNetworking 2.0AFNetworking 2.0總是返回403
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];
做了JSON的GET請求,但它總是與此錯誤返回403:不可接受的內容類型:text/html的
怪異事情是,我與可可GraphicalHttpClient做了同樣的要求,它的確定和返回JSON響應與此:
內容類型:應用程序/ JSON的;字符集= UTF-8 日期:星期五,2015年9月25日15:28 :27 GMT 傳輸編碼:身份 X-Powered-By:Servlet/2.5 JSP/2.1
非常感謝。
第三方服務器發送給您的禁止錯誤,而不是'AFNetworking'框架......你可能需要從系統管理員爲你要訪問的內容請求許可。 – holex
Add manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@「text/html」] ;.希望它的工作,如果它不工作,你可以發佈你的代碼? –
我試過,但沒有運氣。 – roof