Created
November 30, 2013 07:58
-
-
Save PavelGnatyuk/7716512 to your computer and use it in GitHub Desktop.
Check if a file exists on the web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (BOOL)webFileExists:(NSURL *)url | |
{ | |
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; | |
[request setHTTPMethod:@"HEAD"]; | |
NSHTTPURLResponse* response = nil; | |
NSError* error = nil; | |
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; | |
NSLog(@"Response length: %i", [data length]); | |
NSInteger code = [response statusCode]; | |
[request release]; | |
return ( code != 404 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment