Pdf file downloaded using AFNetworking is not expected file size

When I try to download a PDF file with a URL using AFNetworking, the size of the saved file is about half what I expected. When I make the same request with the curl / standard browser tool, the file size is correct.

How to unzip a file on the fly to be readable? Or does AFNetworking automatically compress a file that it shouldn't?

The following request header is set by default to the AFNetworking client class:

"Accept-Encoding" = gzip; "Accept" = application/json"; 

This is how I extract the file:

 AFHTTPClient *client; // already instantiated & configured NSURLRequest *request = [client requestWithMethod:@"GET" path:requestPath parameters:parameters]; AFHTTPRequestOperation *operation = [client HTTPRequestOperationWithRequest:request success:success failure:failure]; operation.outputStream = [NSOutputStream outputStreamToFileAtPath:localFilePath append:NO]; [self enqueueHTTPRequestOperation:operation]; 

Later, when I check the file size through NSFileManager and through an external tool, the size is 1/2 of what I expect.

When I issue the same request through an HTTP browser client, I do not see anything in the response headers to indicate that the returned content is being compressed.

Response headers sent by the server (verified through the HTTP browser extension tool):

 Transfer-Encoding: chunked Status: 200 OK Content-Transfer-Encoding: binary Content-Disposition: inline; filename="document_sample.pdf" Connection: keep-alive Content-Type: application/pdf Cache-Control: private 

How to upload a file so that it is saved as expected?

+4
source share

Source: https://habr.com/ru/post/1445660/


All Articles