Skip to content

Instantly share code, notes, and snippets.

@mikesaltsman
Created May 15, 2012 19:40
Show Gist options
  • Save mikesaltsman/2704484 to your computer and use it in GitHub Desktop.
Save mikesaltsman/2704484 to your computer and use it in GitHub Desktop.
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