且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Objective-c从URL检查文件大小而不下载

更新时间:2023-11-26 18:20:46

If the server supports it you can make a request to just get the headers (HEAD, as opposed to GET) without the actual data payload and this should include the Content-Length.

If you can't do that then you need to start the download and use expectedContentLength of the NSURLResponse.


Basically, create an instance of NSMutableURLRequest and call setHTTPMethod: with the method parameter set to @"HEAD" (to replace the default which is GET). Then send that to the server as you currently request for the full set of data (same URL).