views:

39

answers:

1

Looking for a way to retrieve a file size from a web server using cocoa/foundation. I know one can use NSURLconnection which will return 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

+3  A: 

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.

zoul
@zoul: Indeed that works. Thanks for your help. Here is what i did:NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:aURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]; [request setHTTPMethod:@"HEAD"];
MikeM