2014-04-11 3 views
2

글꼴 다람쥐 API의 다른 모든 끝점을 사용할 수 있지만 ZIP 글꼴 킷을 반환하는 끝점을 가져올 때마다 Request failed: unacceptable content-type: "application/x-zip" 헤더를 내가 추가 acceptableContentTypes = @"text/html",@"application/x-zip" 각, XML, JSON 및 HTTP에 응답 시리얼을 설정하려고했기 때문에,AFNetworking이 포함 된 .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\"; 

는 나에게 정말 이상한 모습. 내가 뭔가 잘못하고 있는지 또는 API 개발자에게 뭔가 잘못 될 수 있는지 명확히해야하는지 잘 모르겠습니다. 나는 크롬과 컬에서 정확히 동일한 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*)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

질문을 편집하여 다운로드 및 설정하려는 코드를 표시 할 수 있습니까? – Paulw11

+0

@ Paulw11 코드 추가 – mcornell

답변

1

상황을 GET

1) 당신이 치려고하는 URL이 적당해야합니다. 웹 브라우저를 통해 다운로드가 이루어지는 지 확인하십시오.

2) 요청 내 콘텐츠 타입 \"Content-Type\" = \"\\\"application/x-zip\\\"\";

3) AcceptNonJson가 YES로 이루어져야 할 것이다. 데이터를 응답으로 받으려고하면 파싱 할 필요가 없습니다.

+0

URL이 적합합니다. 크롬과 컬링에서 동일한 URL을 사용할 수 있습니다. 요청에 콘텐츠 유형이 있다고 생각하지 않습니까? AFNetworking 2.0을 사용하고 있습니다. AcceptNonJson이 뭔지도 모르겠다. AFNetworking 1.0에 뭔가 있는거야? – mcornell

+0

# 2가 도움이되었는데, 나는 Content-Type이 너무 많은 탈출구를 가지고 있다는 것이 얼마나 이상한 것인지 알았습니다. – mcornell

+0

문제가 해결 되었습니까? – Rajesh

3

반환되는 콘텐츠 형식이 application/x-zip이 아니고 "application-x-zip"이고 HTTPResponseSerializer를 사용해야했습니다.

관련 문제