Created
May 15, 2012 19:40
-
-
Save mikesaltsman/2704484 to your computer and use it in GitHub Desktop.
This file contains 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
NSURL *url = [NSURL URLWithString:@"https://mysite.com/"]; | |
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; | |
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: | |
height, @"user[height]", | |
weight, @"user[weight]", | |
nil]; | |
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/myobject" parameters:params]; | |
AFHTTPRequestOperation *operation = [AFHTTPRequestOperation operationWithRequest:request | |
completion:^(NSURLRequest *req, NSHTTPURLResponse *response, NSData *data, NSError *error) { | |
BOOL HTTPStatusCodeIsAcceptable = [[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)] containsIndex:[response statusCode]]; | |
if (HTTPStatusCodeIsAcceptable) { | |
NSLog(@"Request Successful"); | |
} else { | |
NSLog(@"[Error]: (%@ %@) %@", [request HTTPMethod], [[request URL] relativePath], error); | |
} | |
}]; | |
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; | |
[queue addOperation:operation]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment