我可以使用字体squirrel 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\" = \"PHP/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;
}
// GET
-(AFHTTPRequestOperation*)downloadFontFamily:(FontFamily*)fontFamily withBlock:(void(^)(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);
}];
}
答案 0 :(得分:3)
返回的内容类型不是application/x-zip
它是"application-x-zip"
,我还必须使用HTTPResponseSerializer。
答案 1 :(得分:1)
需要考虑的事项
1)您尝试点击的网址应该是正确的。确保通过网络浏览器进行下载。
2)此请求的内容类型应为\"Content-Type\" = \"\\\"application/x-zip\\\"\";
3)AcceptNonJson应该是YES。由于您将获取数据作为响应,因此您无需解析它们。