我需要检查我的服务器上是否存在不使用缓存的文件。我使用的方法都返回200,即使该文件不存在,所以我只能假设存在缓存问题,或者我的代码存在问题。iPhone SDK远程文件存在,不需要缓存
继承人我的代码︰参数sake..the 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,即使我重命名服务器上的文件。
请显示您的代码。如果我们能看到发生了什么,你将有更好的运气获得答案。 – 2010-08-27 19:46:56