Reputation: 768
I'm able to use every other endpoint of the font squirrel API, but whenever I try to GET the endpoint which returns the zipped fontface kit, I get Request failed: unacceptable content-type: "application/x-zip"
and headers that look like
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\";
it's really odd to me, because I've tried setting the response serializer to XML, JSON, and HTTP, each with acceptableContentTypes = @"text/html",@"application/x-zip"
added. I'm not sure if I'm doing something wrong or if I should ask the API developers to clarify if something could be wrong on their end. I can make the exact same GET request from chrome and curl, and those both work.
-- edit, adding code snippets //init
+(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);
}];
}
Upvotes: 2
Views: 1507
Reputation: 768
The content type being returned wasn't application/x-zip
it was "application-x-zip"
, and I also had to use a HTTPResponseSerializer.
Upvotes: 3
Reputation: 10424
Things to be consider
1) The URL you are trying to hit should be proper. Ensure your download happens through web browser.
2) Your content type of this request should be \"Content-Type\" = \"\\\"application/x-zip\\\"\";
3) AcceptNonJson should be made to YES. Since your going to get Data as response you don't need to parse them.
Upvotes: 1