// WebUtil.h: #import @interface WebUtil : NSObject { NSMutableData *responseData; } @property (nonatomic, retain) NSMutableData *responseData; - (void) performRequest; @end // WebUtil.m #import "WebUtil.h" @implementation WebUtil @synthesize responseData; - (void) performRequest { // create request NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // // create the connection for the request NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { // create NSMutableData to hold the data responseData = [[NSMutableData alloc] retain]; } return; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { // null out response, ready to receive [responseData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [responseData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"Failed nsurl"); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog([NSString stringWithUTF8String:[responseData bytes]] ); [connection release]; } @end