I have a website with a domain and host where I have a '.txt' file that changes with the webpage's activity. I am trying to write a simple program in Objective-C that will read the 'txt' file and write all its content to an 'NSTextField'. Here is the code:
NSError *err = NULL;
NSString *str = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"theurl"] encoding:NSUTF8StringEncoding error:&err];
if(str != NULL)
[_textField setString:str];
if(err != NULL)
NSRunAlertPanel(@"An error has occurred while getting application data.", [err description], @"Ok", nil, nil);
The code works great except that it always gets the data in cache, meaning not the newest version of the file. Even when I'm not connected to internet, an error message doesn't pop up and I end up getting the string from the file. How can I make the program to go find the file on the net instead of the one from the cache?
I know that I can clear the browser cache but it's not a permanent solution, since I would have to clear the cache over and over again.
I have solved the problem by adding an .htaccess
file to the root of my host. In the .htaccess
, file I specified to not save any cached data from the site by the following code:
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments