Skip to content

Instantly share code, notes, and snippets.

@zeayes
Created January 13, 2015 06:25
Show Gist options
  • Save zeayes/04f9c69dfdaaf062f6d3 to your computer and use it in GitHub Desktop.
Save zeayes/04f9c69dfdaaf062f6d3 to your computer and use it in GitHub Desktop.
http get example for objective
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[]) {
@autoreleasepool {
NSError *error;
NSURL *url = [NSURL URLWithString: @"http://127.0.0.1:6100/user/10167/profile/"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval: 10];
NSData *received = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil
error:&error
];
NSString *str = [[NSString alloc] initWithData:received
encoding:NSUTF8StringEncoding
];
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:received
options:kNilOptions
error:&error
];
NSLog(@"json data: %@", data);
NSLog(@"%@", str);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment