The contents of the text file at the URL that iphone will display

Trying to get the contents of a text file at this URL, but it does not seem to work. Any help?

NSURL *url = [NSURL URLwithString:@"http://haproxy.1wt.eu/download/1.9/keep-alive/keep-alive.txt"];
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding];
NSLog(content);

The actual text file will be only 20 words, but this is just an example.

Am I doing it wrong? or is it much more complicated?

+3
source share
1 answer

You were close ...
Capital W in URLWithString
NSError variabel as an error parameter: NSString
Then it should work

NSURL *url = [NSURL URLWithString:@"http://haproxy.1wt.eu/download/1.9/keep-alive/keep-alive.txt"];
NSError* error;
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];

You should also try using ASIHTTPRequest , which is a good wrapper for the CFNetwork API

+11
source

Source: https://habr.com/ru/post/1783103/


All Articles