通过HTTP获取远程文件大小,而无需下载该文件 [英] Get remote file size via HTTP without downloading said file

查看:68
本文介绍了通过HTTP获取远程文件大小,而无需下载该文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以获取(远程,http)文件的大小而无需实际下载吗?

Any way to get the size of a (remote, http) file without actually downloading it?

所有其他类似的问题似乎都围绕着从 didReceiveResponse:中的 NSURLResponse 对象中获取 expectedContentLength ,但是我不想下载该文件,我只想知道它有多大.

All other similar questions seem to revolve around grabbing the expectedContentLength from the NSURLResponse object in didReceiveResponse: but I don't want to download the file, I just want to know how big it is.

推荐答案

尝试发出HEAD请求,它仅返回包含Content-Length标头的标头.

Try to make HEAD request, it returns only headers with Content-Length header included.

~$ curl -I http://google.com/
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Length: 219
...

这篇关于通过HTTP获取远程文件大小,而无需下载该文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆