内容长度未读
我在下载图像之前尝试获取图像的大小时遇到问题。
我正在尝试从 Xcode 中的远程服务器读取图像文件的标头。示例图像的链接位于:http://www.iseivijosdaile.lt/ iPadWS/images/thumbnail_1195165011LIDF-0130.png
终端命令
curl --head http://www.iseivijosdaile.lt/iPadWS/images/thumbnail_1195165011LIDF-0130.png
返回Content-Length: 125803
而以下
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
if ([response respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog([dictionary description]);
}
}
不包含 Content-Length 字段。
为什么会发生这种情况?我该如何解决这个问题?
谢谢!
I have a problem trying to get the size of an image before downloading it.
I am trying to read the headers of image files from a remote server in Xcode. The link to a sample image is here: http://www.iseivijosdaile.lt/iPadWS/images/thumbnail_1195165011LIDF-0130.png
Terminal command
curl --head http://www.iseivijosdaile.lt/iPadWS/images/thumbnail_1195165011LIDF-0130.png
returns Content-Length: 125803
While the following
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
if ([response respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog([dictionary description]);
}
}
does not contain the field Content-Length.
Why is this happenning and how can I solve this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
NSURLResponse *
的 Content-Length 不与其余标头字段一起存储,而是存储在它自己的字段中:Its because Content-Length for a
NSURLResponse *
is not stored with the rest of the header fields, but in it's own field: