Why in my NSURLConnection the incorrect expected contact length is reported.

I have an NSURLConnection and in didReceiveResponseI check [response expectedContentLength]and get really large values, such as 18446744073709551615. There is no way that this is correct. The download is about 3 kilobytes, and when I expect the same request in the violinist, I see the (correct) content length header in the response about 3 kilobytes.

+3
source share
2 answers

The answer associated with the comments is that it was called by gzip. Oddly enough, the meaning for expectedContentLengthseems undesirable and cannot be trusted. If the gzip result is encoded, then NSURLConnectionit cannot correctly determine the size of the unencoded result.

+2
source

To avoid this problem, set the "Accept-Encoding" header field to @ "gzip; q = 0". which tells the server that you are not accepting gzip, and if possible send an uncompressed file.

+3
source

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


All Articles