objective-c - how to handle "too many http redirects" error in objective c
问题描述
i'm currently working on an itunes search app. i'm following the iTunes API documentation (https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/) and AFNetworking sample here (https://github.com/AFNetworking/AFNetworking). But i'm getting an error of "too many http redirects". Here's my code:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"https://itunes.apple.com/search?term=jack+johnson&limit=25"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@ %@", response, responseObject);
}
}];
[dataTask resume];
I've also tried:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"https://itunes.apple.com/search?term=jack+johnson&limit=25"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
} else {
NSLog(@"File downloaded to: %@", filePath);
NSDictionary *result;
NSData *jSONData = [NSData dataWithContentsOfURL:filePath]; // will block if url is not local!
if (jSONData) {
result = [NSJSONSerialization JSONObjectWithData:jSONData options:0 error:NULL];
NSLog(@"%@", result);
}
}
}];
[downloadTask resume];
Thanks in advance for answering. ps. im new here :3
解决方案
推荐阅读
- django - Django CMS 联系表
- c++ - 如何从主窗口中的另一个对话框访问值
- javascript - 为弹性应用搜索构建 gatsby 插件 - 获取 graphql 查询
- python - 使用 Python 创建 YAML:Cloudformation 模板
- android - 更改 Android CalendarView 箭头颜色/图标并替换选定的圆形
- javascript - 创建地图后如何访问和更新地图的值?
- azure-devops - VSTS 管道步骤 PublishPipelineArtifact 在清单部署任务上失败
- python - 为什么我不能在 django 中使用 pandas 指定媒体文件夹中的文件位置?
- python - 我正在尝试使用 Python-selenium 从 iframe 元素中的“src”中提取链接,但最终出现 no such element 错误
- sql-server - SSIS自定义数据流组件循环输入管道缓冲区不止一次