我可以使用字体松鼠 API 的所有其他端点,但是每当我尝试获取返回压缩字体套件的端点时,我得到 Request failed: unacceptable content-type: "application/x -zip"
和看起来像
status code: 200, headers {
Connection = \"keep-alive\";
\"Content-Disposition\" = \"attachment; filename=\\\"1942-report-fontfacekit.zip\\\"\";
\"Content-Length\" = 284695;
\"Content-Transfer-Encoding\" = binary;
\"Content-Type\" = \"\\\"application/x-zip\\\"\";
Date = \"Fri, 11 Apr 2014 23:21:37 GMT\";
Expires = 0;\n Pragma = \"no-cache\";
Server = \"nginx admin\";
\"Set-Cookie\" = \"admin_rm=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=www.fontsquirrel.com, sitetoken=9e7e8c6f53ffe68791fa9e6a2531fe88; expires=Mon, 08-Apr-2024 23:21:37 GMT; path=/; domain=www.fontsquirrel.com, tracker=b13703d93358d65f09306b1b09d6e072; path=/; domain=www.fontsquirrel.com\";
\"X-Cache\" = \"HIT from Backend\";
\"X-Powered-By\" = \"HP/5.3.23\";
\"X-UA-Compatible\" = \"IE=Edge,chrome=1\";
这对我来说真的很奇怪,因为我尝试将响应序列化程序设置为 XML、JSON 和 HTTP,每个都使用 acceptableContentTypes = @"text/html",@"application/x-zip"
添加。我不确定我是否做错了什么,或者我是否应该要求 API 开发人员澄清他们最终是否有问题。我可以从 chrome 和 curl 发出完全相同的 GET 请求,并且它们都可以工作。
-- 编辑,添加代码片段 //初始化
+(instancetype)sharedManager {
static APIManager *manager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager = [[APIManager alloc] initWithBaseURL:[NSURL URLWithString"http://www.fontsquirrel.com/"]];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects"text/html",@"application/x-zip",nil];
});
return manager;
}
//获取
-(AFHTTPRequestOperation*)downloadFontFamilyFontFamily*)fontFamily withBlockvoid(^)(UIFont *UIFont, NSError *error))callback {
return [self GET:FORMAT(@"fontfacekit/%@",fontFamily.familyURLName) parameters:nil success:^(AFHTTPRequestOperation *operation,
id responseObject) {
NSLog(@"%@%@",[responseObject class],responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"FAIL %@\n%@",error.localizedDescription,error.userInfo);
}];
}
返回的内容类型不是 application/x-zip
而是 "application-x-zip"
,而且我还必须使用 HTTPResponseSerializer。
关于ios - 无法使用 AFNetworking 下载 .zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23024220/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |