gpt4 book ai didi

iphone - 为什么 [response expectedContentLength] 总是返回 -1

转载 作者:技术小花猫 更新时间:2023-10-29 11:12:40 24 4
gpt4 key购买 nike

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse    *)response {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
if([recievedData length]) [ recievedData setLength:0 ];

download_size =[response expectedContentLength];
}

我有这个代码。下载大小是 NSInteger。expectedContentLenght 总是返回:-1。也许有人知道为什么?我试过使用long,但效果是一样的。

感谢您的帮助。

最佳答案

预期的内容长度仅在服务器提供时设置,例如通过 Content-Length 响应 header 。 -1 大小表示预期的内容大小未知。

如果您在您的请求中设置了Accept-Encoding: gzip,URL 加载系统会撒谎并告诉您期望的大小是-1,无论服务器发送什么Content-Length。这是因为它在将数据传递给您之前对其进行了解压缩,但是直到所有数据都已下载它才能知道最终未压缩的大小,这在您收到此回调之后很好。

关于iphone - 为什么 [response expectedContentLength] 总是返回 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7417610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com