目前,我正在尝试通过URLConnection和URlRequest读取本地服务器中的文件。它看起来像它应该工作的那样,直到文件中的更改在我再次执行请求时没有任何影响。下面是我如何构建请求的代码:
-(void)openURLConnectionWithString:(NSString *)urlString{
NSTimeInterval timeout= 120;
self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:timeout];
self.urlConnection = [NSURLConnection connectionWithRequest:request delegate:self];
if(urlConnection){
NSLog(@"Connecting...");
self.receivedData = [NSMutableData data];
}else{
NSLog(@"Connection failed!");
}
}下面是我如何使用包含上述函数的类:
AsyncScheduleParser *getSchedule = [[AsyncScheduleParser alloc] init];
getSchedule.delegate = self;
[getSchedule openURLConnectionWithString:@"http://localhost/scheduleC.txt"];
[getSchedule release];只有当我更改文件的名称时,这些更改才会在我再次读取它时出现。
发布于 2011-11-29 03:56:12
在请求完成后,不要忘记清理所有相关的对象(比如self.receivedData)。最好的解决方案是为您正在执行的每个请求创建一个新对象,并在完成后释放该对象。
https://stackoverflow.com/questions/8301488
复制相似问题