Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 响应expectedContentLength返回-1_Iphone_Ios5_Nshttpurlresponse - Fatal编程技术网

Iphone 响应expectedContentLength返回-1

Iphone 响应expectedContentLength返回-1,iphone,ios5,nshttpurlresponse,Iphone,Ios5,Nshttpurlresponse,您好,当我从Web服务加载数据时,我需要创建progressView 实际上,expectedContentLength始终返回-1 在经历了很多类似的问题之后,我的Web服务似乎从未发送过内容长度: 然后我用CURL检查,结果如下: < HTTP/1.1 200 OK < Date: Thu, 21 Jun 2012 10:04:39 GMT < Server: Apache/2.2.16 (Debian) < X-Powered-By: PHP/5.3.3-7+squ

您好,当我从Web服务加载数据时,我需要创建progressView

实际上,expectedContentLength始终返回-1

在经历了很多类似的问题之后,我的Web服务似乎从未发送过内容长度:

然后我用CURL检查,结果如下:

< HTTP/1.1 200 OK
< Date: Thu, 21 Jun 2012 10:04:39 GMT
< Server: Apache/2.2.16 (Debian)
< X-Powered-By: PHP/5.3.3-7+squeeze9
< cache-control: no-cache
< Vary: Accept-Encoding
< Content-Type: text/html; charset=UTF-8
< Content-Length: 3239  
< Connection: Keep-Alive
< Set-Cookie: PHPSESSID=u4o4i9dofdgnkfmtnf163635j6; path=/

有人已经看到这个问题了吗?

我也遇到了同样的问题,似乎预期的文件大小未知,这就是它返回-1的原因


请参阅类似的威胁

好的,我已经自己解决了这是我真正的问题和解决方案:

当我问卷曲,我可以得到长度没有问题

但当我使用NSURL连接时

NSURLConnection *c = [[NSURLConnection alloc] initWithRequest:req delegate:self];
响应将被压缩为“Gzip”(不要问我为什么)。如果响应是用Gzip编码的,则不可能知道长度,那么“expectedContentLength”返回-1[response allHeaderFields]中缺少“内容长度”

如果您真的想获得长度,可以简单地强制不使用Gzip,如下所示:

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

尝试:
NSLog(@“%@,[response allHeaderFields])
并查看响应对象是否实际具有
内容长度
标题字段。此处的代码示例“NSURLResponse”没有“allHeaderFields”属性。我如何知道预期长度?我使用的是NSHTTPURLResponse,而不是NSURLResponse
[req setValue:@"" forHTTPHeaderField:@"Accept-Encoding"];