Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLConnection sendSynchronousRequest - missing data

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: 
like image 352
Frederik Avatar asked Jun 15 '12 09:06

Frederik


1 Answers

pass in NSError to check if error occurred

NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
like image 94
Wubao Li Avatar answered Nov 18 '22 00:11

Wubao Li