Retrieve file size from web server
Looking for a way to retrieve a file size from a web server using cocoa/foundation. I know one can use NSURLconnection which will ret开发者_开发技巧urn NSURLResponse that contains the file size. Is there any other way to get the size. I'm looking for a synchronous way of doing it so when i do [myClass getsize] the size is returned.
Thanks
You can use a NSMutableURLRequest
to send a HTTP HEAD request (there’s a method called setHTTPMethod
). You’ll get the same response headers as with GET, but you won’t have to download the whole resource body. And if you want to get the data synchronously, use the sendSynchronousRequest…
method of NSURLConnection
.
精彩评论