Created
March 8, 2015 02:08
-
-
Save shibukawa/f53660dd4ebbafd901ab to your computer and use it in GitHub Desktop.
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
#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