Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Monkaaay

macrumors 6502
Original poster
Jun 19, 2006
258
0
Richmond, VA
I'm trying to read the contents of a URL and I came across the NSURLRequest and NSURLConnection objects. I have a NSMutableData object filled with the results but I can't find a way to print that data to the screen. Any ideas?
 

Monkaaay

macrumors 6502
Original poster
Jun 19, 2006
258
0
Richmond, VA
Well, I found this solution but I wish it were more elegant.

Code:
unsigned char byteBuffer[[receivedData length]];
[receivedData getBytes:byteBuffer];
NSLog(@"Output: %s", (char *)byteBuffer);
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
How about

NSString *s = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSLog(@"%@", s);
[s release];


Not sure if that's really any better though.
 

GeeYouEye

macrumors 68000
Dec 9, 2001
1,669
10
State of Denial
HiRez said:
How about

NSString *s = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSLog(@"%@", s);
[s release];


Not sure if that's really any better though.
Or just use stringWithContentsOfURL:encoding: (I think that's the method...)
Also, NSLog(s) would work as well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.