Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's first worth adding (as this answer is still popular 6 years after I initially wrote it...) that the first thing you should consider is whether you should even use AFNetworking. NSURLSession was added in iOS 7 and means you don't need to use AFNetworking in many cases - and one less third party library is always a good thing.</p> <p>For AFNetworking 3.0:</p> <pre><code>AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; NSDictionary *params = @{@"user[height]": height, @"user[weight]": weight}; [manager POST:@"https://example.com/myobject" parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(NSURLSessionTask *operation, NSError *error) { NSLog(@"Error: %@", error); }]; </code></pre> <p>For AFNetworking 2.0 (and also using the new NSDictionary syntax):</p> <pre><code>AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *params = @{@"user[height]": height, @"user[weight]": weight}; [manager POST:@"https://example.com/myobject" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; </code></pre> <p>If you are stuck using AFNetworking 1.0, you need to do it this way:</p> <pre><code>NSURL *url = [NSURL URLWithString:@"https://example.com/"]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: height, @"user[height]", weight, @"user[weight]", nil]; [httpClient postPath:@"/myobject" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSLog(@"Request Successful, response '%@'", responseStr); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"[HTTPClient Error]: %@", error.localizedDescription); }]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload