why [response expectedContentLength] always return -1

前端 未结 2 1209
粉色の甜心
粉色の甜心 2020-11-29 04:21
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse    *)response {
    [UIApplication sharedApplication].networkActivityIndicatorVisi         


        
相关标签:
2条回答
  • 2020-11-29 04:48

    As long as I know, NSURLResponse does not update that property. You need to use NSHTTPURLResponse instead...

    0 讨论(0)
  • 2020-11-29 04:58

    The expected content length is only set when the server provides it, such as by a Content-Length response header. A -1 size means the expected content size is unknown.

    If you set Accept-Encoding: gzip on your request, the URL loading system will fib and tell you the expected size is -1, no matter what Content-Length the server sends. This is because it decompresses the data before passing it to you, but it can't know the final uncompressed size till all the data has been downloaded, which is well after you receive this callback.

    0 讨论(0)
提交回复
热议问题