Skip to content

Instantly share code, notes, and snippets.

@fawkeswei
Created September 13, 2012 14:39
Show Gist options
  • Save fawkeswei/3714727 to your computer and use it in GitHub Desktop.
Save fawkeswei/3714727 to your computer and use it in GitHub Desktop.
How to post json data using AFNetworking
NSURL *url = [NSURL URLWithString:@"http://someurl.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
// don't forget to set parameterEncoding!
httpClient.parameterEncoding = AFJSONParameterEncoding;
NSDictionary *params = @{@"key" : @"value"};
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"" parameters:params];
AFHTTPRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:nil failure:nil];
[operation start];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment