Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can override the default behavior of your request being used with <code>AFNetworking</code> to process as a POST.</p> <pre><code>NSURLRequest *request = [client requestWithMethod:@"POST" path:path parameters:nil]; </code></pre> <p>This assumes you have overridden the default <code>AFNetworking</code> setup to use a custom client. If you aren't, I would suggest doing it. Just create a custom class to handle your network client for you.</p> <p><strong>MyAPIClient.h</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "AFHTTPClient.h" @interface MyAPIClient : AFHTTPClient +(MyAPIClient *)sharedClient; @end </code></pre> <p><strong>MyAPIClient.m</strong></p> <pre><code>@implementation MyAPIClient +(MyAPIClient *)sharedClient { static MyAPIClient *_sharedClient = nil; static dispatch_once_t oncePredicate; dispatch_once(&amp;oncePredicate, ^{ _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:webAddress]]; }); return _sharedClient; } -(id)initWithBaseURL:(NSURL *)url { self = [super initWithBaseURL:url]; if (!self) { return nil; } [self registerHTTPOperationClass:[AFJSONRequestOperation class]]; [self setDefaultHeader:@"Accept" value:@"application/json"]; self.parameterEncoding = AFJSONParameterEncoding; return self; } </code></pre> <p>Then you should be able to fire off your network calls on the operation queue with no problem.</p> <pre><code> MyAPIClient *client = [MyAPIClient sharedClient]; [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; [[AFNetworkActivityIndicatorManager sharedManager] incrementActivityCount]; NSString *path = [NSString stringWithFormat:@"myapipath/?value=%@", value]; NSURLRequest *request = [client requestWithMethod:@"POST" path:path parameters:nil]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { // code for successful return goes here [[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount]; // do something with return data }failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { // code for failed request goes here [[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount]; // do something on failure }]; [operation start]; </code></pre>
    singulars
    1. This table or related slice is empty.
    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