NSURLConnection sendSynchronousRequest - missing data

I am trying to read a text file using a synchronous request. This does not work, but I do not receive any errors or warnings.

Can someone enlighten me about what I am 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: 
+5
source share
1 answer

pass NSErrorto check if an error has occurred

NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
+8
source

All Articles