【发布时间】:2010-08-27 19:38:16
【问题描述】:
我需要在不使用缓存的情况下检查我的服务器上是否存在文件。我用的方法都是返回200,即使文件不存在,所以只能假设是缓存有问题,或者是我的代码有问题。
这是我的代码:出于参数考虑..此示例中的 URL 已更改,但我的代码中的 url 是正确的。
NSString *auth = [NSString stringWithFormat:@"http://www.mywebsite.com/%@.txt",[self aString]];
NSURL *authURL = [NSURL URLWithString:auth];
NSURLRequest* request = [NSURLRequest requestWithURL:authURL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:5.0];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request
delegate:self];
NSHTTPURLResponse* response = nil;
NSError* error = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"statusCode = %d", [response statusCode]);
if ([response statusCode] == 404)
NSLog(@"MISSING");
else
NSLog(@"EXISTS");
即使我在服务器上重命名文件,响应总是 200。
【问题讨论】:
-
请出示您的代码。如果我们能看到正在发生的事情,您将获得更好的答案。