Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-11-2008, 08:40 PM   #1 (permalink)
CoffeeKid
Guest
 
Posts: n/a
Default Pulling Data From A Web Page

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
  Reply With Quote
 

» Advertisements
» Stats
Members: 158,557
Threads: 89,126
Posts: 380,253
Top Poster: BrianSlick (7,103)
Welcome to our newest member, wTaylorDaviesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:18 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.