I would create an APIClient class for all requests instead of creating a new client every time I make a request.
See: https://github.com/AFNetworking/AFNetworking/tree/master/Example/Classes AFTwitterAPIClient.h and AFTwitterAPIClient.m
but based on your question. I believe the code will look something like this. (The code has not been tested)
NSURL *url = [NSURL URLWithString:@"http://server.com"]; AFHTTPClient *client = [[AFHTTPClient alloc]initWithBaseURL:url]; //depending on what kind of response you expect.. change it if you expect XML [client registerHTTPOperationClass:[AFJSONRequestOperation class]]; NSDictionary *params = [[NSDictionary alloc]initWithObjectsAndKeys: @"NUMBER",@"number", @"NAME",@"name", @"32.5713",@"lat", @"60.3926",@"lon", nil]; [client putPath:@"users" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"success"); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"failure"); }];
As for the mail request, just use postPath instead of putPath and it will work fine. :)
Hope I helped.
Hi,
Steve0hh
source share