I'm trying to read a text file using a synchronous request. It doesn't work but I get no errors or warnings either.
Can anyone enlighten me on what I'm doing wrong, please?
NSString *url = @"http://pappons.com/test.txt" ;
NSLog(@"getHTTPData: %@" , url ) ;
NSURLResponse* response = nil;
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData* data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil] ;
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog( @"data: %@" , myString ) ;
output:
2012-06-15 11:33:42.209 FrederikTest[1365:707] getHTTPData: http://pappons.com/test.txt
2012-06-15 11:33:42.306 FrederikTest[1365:707] data:
pass in NSError
to check if error occurred
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With