Skip to content

Instantly share code, notes, and snippets.

@maggix
Created June 2, 2014 21:11
Show Gist options
  • Select an option

  • Save maggix/be09272106d20729190d to your computer and use it in GitHub Desktop.

Select an option

Save maggix/be09272106d20729190d to your computer and use it in GitHub Desktop.
A basic NSURLRequest
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.yourserver.com/yourRestServer.php"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:100];
[request setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if(!error)
{
@try {
__autoreleasing NSError *parsingError = [[NSError alloc] init];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&parsingError];
NSLog(@"NSJSONSerialization Dict: %@", dict);
}
@catch (NSException *exception) {
NSLog(@"Exception: %@", [exception description]);
}
@finally {
//We'll never get here
}
}
else{
NSLog(@"Response Error: %@", [error description]);
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment