1

I have a simple command line application to test the presence of files. The files are very large, however, and I would like to check that they are there without downloading the whole file. This is what I have but it downloads each file:

            NSURL *url = [NSURL URLWithString:downloadPath];
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            NSURLResponse *response = nil;
            NSError **error=nil; 
            NSData *data=[[NSData alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:error]];

            NSInteger httpStatus = [((NSHTTPURLResponse *)response) statusCode];

            if(httpStatus == 404)
            {
                NSLog(@"%@ NOT FOUND!",[productDic objectForKey:@"fileName"]);

            }

The files I am looking for are .zip and are not found locally.

1 Answer 1

5

If you make a HEAD request instead of a GET request, you'll probably get what you're after:

NSMutableURLRequest *request = [[NSURLRequest requestWithURL:url] mutableCopy];
[request setHTTPMethod:@"HEAD"];
[request autorelease];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.