AFNetworking 2.0 Send Post Request with URL Parameters

后端 未结 6 2172
忘掉有多难
忘掉有多难 2020-12-19 05:16

How do I send a POST request with AFNetworking 2.0 with all the parameters in the URL like such:

http://www.myserver.com?api_key=something&

6条回答
  •  余生分开走
    2020-12-19 05:45

    #import "AFNetworking.h"
    ...
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        NSDictionary *params = @{@"param1": value1,
                                     @"param2": value};
        manager.responseSerializer = [AFJSONResponseSerializer serializer]; // if response JSON format
        [manager POST:@"http://domain.com/backend.php" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    
        NSLog(@"%@", responseObject);
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];    
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    
        NSLog(@"%@", error);
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
        }];
    

    try this

提交回复
热议问题