response expectedContentLength return -1

旧城冷巷雨未停 提交于 2019-11-27 09:10:05

Ok i've fix it myself here is my real problem and a solution :

When i ask with Curl i can get the length no problem.

But when i use NSurlConnection

NSURLConnection *c = [[NSURLConnection alloc] initWithRequest:req delegate:self];

The response will be compress with "Gzip" (don't ask me why). And if the response is encode with Gzip it's impossible to know the length, then "expectedContentLength" return -1. And "Content-Length" is absent from [response allHeaderFields].

If you really want to get the length you can simply force to not use Gzip like this :

[req setValue:@"" forHTTPHeaderField:@"Accept-Encoding"];
Mike

I got the same problem it seems like the expected file size is unknown thats why it returns -1.

see similar threat why [response expectedContentLength] always return -1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!