ios - 无法使用 AFNetworking 下载 .zip 文件
<p><p>我可以使用字体松鼠 API 的所有其他端点,但是每当我尝试获取返回压缩字体套件的端点时,我得到 <code>Request failed: unacceptable content-type: "application/x -zip"</code>
和看起来像 </p> 的标题
<pre><code>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\";
</code></pre>
<p>这对我来说真的很奇怪,因为我尝试将响应序列化程序设置为 XML、JSON 和 HTTP,每个都使用 <code>acceptableContentTypes = @"text/html",@"application/x-zip"</code>添加。我不确定我是否做错了什么,或者我是否应该要求 API 开发人员澄清他们最终是否有问题。我可以从 chrome 和 curl 发出完全相同的 GET 请求,并且它们都可以工作。</p>
<p>-- 编辑,添加代码片段
//初始化</p>
<pre><code>+(instancetype)sharedManager {
static APIManager *manager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager = [ initWithBaseURL:];
manager.responseSerializer.acceptableContentTypes = ;
});
return manager;
</code></pre>
<p>}</p>
<p>//获取</p>
<pre><code>-(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);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"FAIL %@\n%@",error.localizedDescription,error.userInfo);
}];
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>返回的内容类型不是 <code>application/x-zip</code> 而是 <code>"application-x-zip"</code>,而且我还必须使用 HTTPResponseSerializer。</p></p>
<p style="font-size: 20px;">关于ios - 无法使用 AFNetworking 下载 .zip 文件,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23024220/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23024220/
</a>
</p>
页:
[1]