Skip to content

Instantly share code, notes, and snippets.

@shibukawa
Created March 8, 2015 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shibukawa/f53660dd4ebbafd901ab to your computer and use it in GitHub Desktop.
Save shibukawa/f53660dd4ebbafd901ab to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
BOOL shouldKeepRunning = YES;
int main(int argc, char *argv[]) {
@autoreleasepool {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:18888"]];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask* task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
shouldKeepRunning = NO;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"Status: %ld", httpResponse.statusCode);
NSDictionary *headers = httpResponse.allHeaderFields;
for (id key in headers) {
NSLog(@"%@: %@", key, [headers objectForKey:key]);
}
if(error == nil) {
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@", text);
}
}];
[task resume];
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while (shouldKeepRunning && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment