Create an NSURLConnection to get the URL. Set HTTPMethod from NSURLRequest to "HEAD" instead of "GET" . In the delegate method connection:didReceiveResponse: check statusCode NSHTTPURLResponse for 200 or another success response.
-(void) queryResponseForURL:(NSURL *)inURL { NSMutableURLRequest request = [NSMutableURLRequest requestWithURL:inURL]; [request setHTTPMethod:@"HEAD"]; NSURLConnection connection = [NSURLConnection connectionWithRequest:request delegate:self];
There may be other status codes that you would consider success, for example 301.
Part of the HTTP protocol sets the request method. GET and POST are the two most common, but there are several others, including HEAD. HEAD says it sends the same response you would send for a GET, but do not send it. In your case, the body is image data. Therefore, if HEAD succeeds, you can assume that GET will also succeed in the same way, at least in the case of finding a static resource.
source share