Hi Everyone,
I'm trying to use the CFHTTPRequest library to pull data from a web page. All the web page has is a pipe deliminated string of some information about our server status. I want to pull this into the iPhone and display it in a pretty gui interface.
My issue is that i can't figure out how to get the body of the web page. I've looked through a few examples and I keep getting lost. Below is the code i'm using, please give me some idea on how i would get the body, and then throw it into a string where i can then put the data into variables within a class.
Code:
CFHTTPMessageRef request;
CFReadStreamRef stream;
//init: url is a string like "www.someplace.com"
NSString *theURL = [NSString stringWithFormat:@"http://%@", url];
NSURL *urlObj = [NSURL URLWithString:theURL];
request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), (CFURLRef)urlObj, kCFHTTPVersion1_0);
//fetch
stream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault,request);
CFReadStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFHTTPMessageRef response = (CFHTTPMessageRef) CFReadStreamCopyProperty(stream, kCFStreamPropertyHTTPResponseHeader);
//not sure if this is correct :(
CFDataRef *body = CFHTTPMessageCopyBody(response);
//now what?
Am I heading in the right direction? Or is there a better way to do this?
If I am doing it right, how do I turn body into a string of actual text that I can manipulate?
Thanks,
CoffeeKid