0
I’m testing Aftnetworking to download images from a backend, but I’m having errors downloading images.
I tested several implementations, with this implementation presents error of content not accepted.
Below is the last implementation I did of testing:
NSString* urlImagem = @"http://lojacliente.goldarkapi.com/pizzas/54bf3e3a657f6f2c04a81afd/imagem";
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
operationManager.responseSerializer = [AFImageResponseSerializer serializer];
operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
operationManager.requestSerializer = [AFJSONRequestSerializer serializer];
[operationManager.requestSerializer setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
[operationManager.requestSerializer setValue:@"zRWGVZ0HEpSzsb1ZOYMYHCwL6q54qa2x3y3JlNmCN61d1SCmfRDfnbFHteu/R50N29bOQJv8IgG6aLD4y8dNWQ==" forHTTPHeaderField:@"X-Api-Token"];
[operationManager GET:urlImagem parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failure. Error:%@",error);
}];
ERROR:
Gdrequestimageaftnetworking[1647:65915] Ailure. Error:Error Domain=com.alamofire.error.serialization.Response Code=-1016 "Request failed: Unacceptable content-type: image/jpeg" Userinfo=0x78604030 {com.alamofire.serialization.response.error.Response= { URL: http://lojacliente.goldarkapi.com/pizzas/54bf3e3a657f6f2c04a81afd/imagem } { status code: 200, headers { "Access-Control-Allow-Credentials" = "true, true"; "Access-Control-Allow-Headers" = "Content-Type, Content-Length, Depth, User-Agent, X-Requested-With, X-Requested-By, If-Modified-Since, X-Access-Token, X-Fileencoding, Cache-Control"; "Access-Control-Allow-Methods" = "GET,PUT,POST,DELETE, OPTIONS, HEAD"; "Access-Control-Allow-Origin" = "*"; Connection = "Keep-Alive"; "Content-Length" = 25553; "Content-Type" = "image/jpeg"; Date = "Fri, 30 Jan 2015 16:49:36 GMT"; Etag = "5c08b1f8fc6e9943027d4062badbd5d60aca31f0 ""; Server = "Nginx/1.4.1 (Ubuntu)"; } }, Nserrorfailingurlkey=http://lojacliente.goldarkapi.com/pizzas/54bf3e3a657f6f2c04a81afd/imagem, Nslocalizeddescription=Request failed: Unacceptable content-type: image/jpeg, com.alamofire.serialization.response.error.data=
How could you correctly set the request header setting with Token?
What happens when you remove the
content-type
of the requisition?– André Ribeiro
James, if after applying the suggestions to correct your question there was another error, there was no need to change your whole question, causing the André was out of coherence. You could have just added the information of the new error in the question.
– Paulo Rodrigues
Yes sorry. It wasn’t intensional. @Andréribeiro, thank you, your reply helped me refine the result.
– Tiago Amaral