Posting JSON data using AFNetworking 2.0

后端 未结 5 795
误落风尘
误落风尘 2020-11-28 23:13

I have a web script which accepts JSON string as input through HTTP POST request. I have came across several AFNetworking 1.x example for the same , can anybody please point

5条回答
  •  离开以前
    2020-11-29 00:01

    If you want to post json to server, you should post your parameters use this way below.

    Use this way , you can then find out the "Content-Type" in your request header is "application/json".

    AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    manager.requestSerializer = serializer;
    
     NSDictionary *paras = @{@"uid" : @(10020)};
    
    [manager POST:@"http://your.request.url" parameters:paras success:^(AFHTTPRequestOperation *operation, id responseObject) {
    
    
    
    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    
        NSLog(@"the falire is %@", error);
    
    }];
    

    May this help. :)

提交回复
热议问题