You can either use NSURLRequest or NSMutableURLRequest
the difference is that with NSMutableURLRequest you can change the url the method etc.
I will use the NSMutableURLRequest
Supposing you have a class implementation
#import "UrlFetcher.h" @implementation UrlFetcher -(void)setUrl:(NSString *)url { twitterUrl = [NSURL URLWithString:url]; } -(void)fetchandParse { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:twitterUrl]; [request setHTTPMethod:@"GET"]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"didReceiveResponse"); } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog(@"got data"); NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(result); } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { } @end
Since you set as the delegate the class where the method is called you need to implement the
methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {} - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{} - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{} - (void)connectionDidFinishLoading:(NSURLConnection *)connection{}