Created
November 30, 2014 22:44
-
-
Save joshpuckett/46f6eec597093bc6bb13 to your computer and use it in GitHub Desktop.
NSURLConnection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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