开发者

Get remote file size via HTTP without downloading said file

开发者 https://www.devze.com 2023-01-09 20:51 出处:网络
Any way to get the size of a (remote, http) file without actually downloading it? All other similar questions seem to revolve around grabbing the expectedContentLength from the NSURLResponse object i

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

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开发者_JAVA技巧 want to know how big it is.


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
...
0

精彩评论

暂无评论...
验证码 换一张
取 消