Created
November 7, 2013 18:32
-
-
Save krhoyt/7359548 to your computer and use it in GitHub Desktop.
Plain HTTP GET request.
This file contains 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
- ( NSString * ) loadFileHTTPGet : ( NSString * ) url | |
{ | |
NSArray * crayola; | |
NSArray * parts; | |
NSData * get; | |
NSError * error; | |
NSHTTPURLResponse * response; | |
NSMutableURLRequest * request; | |
NSString * contents; | |
// Load a file over HTTP GET | |
request = [[NSMutableURLRequest alloc] init]; | |
[request setHTTPMethod : @"GET"]; | |
[request setURL:[NSURL URLWithString : url]]; | |
error = [[NSError alloc] init]; | |
response = nil; | |
get = [NSURLConnection sendSynchronousRequest : request returningResponse : &response error : &error]; | |
if( [response statusCode] != 200 ) | |
{ | |
NSLog( @"Error making HTTP request: %@", error ); | |
} else { | |
contents = [[NSString alloc] initWithData : get encoding:NSUTF8StringEncoding]; | |
NSLog( @"%@", contents ); | |
// Parse basic CSV | |
crayola = [contents componentsSeparatedByString : @"\r"]; | |
NSLog( @"%lu", (unsigned long)[crayola count] ); | |
for( NSString * item in crayola ) | |
{ | |
parts = [item componentsSeparatedByString : @","]; | |
NSLog( @"Name: %@, Hex: %@, Year: %@", [parts objectAtIndex : 0], [parts objectAtIndex : 1], [parts objectAtIndex : 6] ); | |
} | |
} | |
return contents; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment