【发布时间】:2012-06-23 13:28:30
【问题描述】:
您好,当我从我的 web 服务加载数据时,我需要创建一个 progressView。
实际上,expectedContentLength 总是返回 -1。
看了很多类似的问题后,看起来我的网络服务从未发送过 Content-Length:.
然后我用 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=/
这是我捕捉长度的代码
long long expectDataSize;
long long currentDataSize;
....
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
{
NSLog(@"expect content length %lld", [response expectedContentLength]);
expectDataSize = [response expectedContentLength];
currentDataSize = 0;
}
有人已经看到这个问题了吗?
【问题讨论】:
-
尝试:
NSLog(@"%@", [response allHeaderFields]);,看看响应对象是否真的有Content Length这个头域。
标签: iphone ios5 nshttpurlresponse