Skip to main content
added 64 characters in body
Source Link
Brodie
  • 3.5k
  • 8
  • 44
  • 62

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.

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"]);

            }

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.

Source Link
Brodie
  • 3.5k
  • 8
  • 44
  • 62

Objective-C checking if URL exists in Command Line application

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"]);

            }