Skip to content

Instantly share code, notes, and snippets.

@PavelGnatyuk
Created November 30, 2013 07:58
Show Gist options
  • Save PavelGnatyuk/7716512 to your computer and use it in GitHub Desktop.
Save PavelGnatyuk/7716512 to your computer and use it in GitHub Desktop.
Check if a file exists on the web
+ (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