开发者

Retrieve file size from web server

开发者 https://www.devze.com 2022-12-28 23:02 出处:网络
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 th

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.

0

精彩评论

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