Skip to content

Instantly share code, notes, and snippets.

@ttran4040
Last active August 29, 2015 14:03
Show Gist options
  • Save ttran4040/a7b5f08319e0b271ffdc to your computer and use it in GitHub Desktop.
Save ttran4040/a7b5f08319e0b271ffdc to your computer and use it in GitHub Desktop.
Unirest Asynchronous Requests
NSDictionary* headers = @{@"accept": @"application/json"};
NSDictionary* parameters = @{@"parameter": @"value", @"foo": @"bar"};
[[UNIRest post:^(UNISimpleRequest* request) {
[request setUrl:@"http://httpbin.org/post"];
[request setHeaders:headers];
[request setParameters:parameters];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
// This is the asyncronous callback block
NSInteger* code = [response code];
NSDictionary* responseHeaders = [response headers];
UNIJsonNode* body = [response body];
NSData* rawBody = [response rawBody];
NSDictionary *json_response = response.body.JSONObject;
NSLog(@"JSON State Result:%@", json_response[@"status_code"]);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment