Skip to content

Instantly share code, notes, and snippets.

@joshpuckett
Created November 30, 2014 22:44
Show Gist options
  • Save joshpuckett/46f6eec597093bc6bb13 to your computer and use it in GitHub Desktop.
Save joshpuckett/46f6eec597093bc6bb13 to your computer and use it in GitHub Desktop.
NSURLConnection
-(void)getRequest
{
NSURL *url = [NSURL URLWithString:@"https://www.goodreads.com/search.xml?key=O719PsMfvl9e19FFt8LmEg&q=common+sense+mutual+funds"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/xml" forHTTPHeaderField:@"accept"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
(void)[NSURLConnection connectionWithRequest:request delegate:self];
}
#pragma mark - NSURLConnection Delegates
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"did fail because %@", [error localizedDescription]);
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[_responseData setLength:0];
NSLog(@"did receive response ");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[_responseData appendData:data];
NSLog(@"did receive data");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"did finish loading");
NSLog(@"%@",_responseData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment