开发者

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 chec开发者_开发知识库k 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.


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜