Skip to content

Instantly share code, notes, and snippets.

@moriyoshi
Forked from shibukawa/test.m
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moriyoshi/2d7f8e08cf3431c1097a to your computer and use it in GitHub Desktop.
Save moriyoshi/2d7f8e08cf3431c1097a 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://www.example.com/"]];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask* task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
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);
}
dispatch_sync(dispatch_get_main_queue(), ^(){ shouldKeepRunning = NO; });
}];
[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