在Objective-C中使用Afnetworking的发布方法 [英] Post method using Afnetworking in Objective-C

查看:120
本文介绍了在Objective-C中使用Afnetworking的发布方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Afnetworking将代码编写为发送以下JSON格式的POST方法的代码.

How to write the code to sending POST method for the below JSON format using Afnetworking.

{
Media
  {
      Photo : image.jpg, 
      UserId : 2
  },
Personal
  {
      Name : aaa, 
      Age   : 30
  }, 
Education
  {
    College : xxx, 
    Course : yyy    

  }, 
} 

推荐答案

首先制作要发送的参数字典

Firstly make a dictionary of params you want to send

NSDictionary *params = @{
                                     @"contact_no":@"9898989898",
                                     @"password":@"••••••••••"
                                     };

然后编写以下代码

AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
    operationManager.requestSerializer = [AFJSONRequestSerializer serializer];
    operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
operationManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
        [operationManager POST:urlString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject){
            NSLog(@"%@",responseObject);

        } failure:^(AFHTTPRequestOperation *operation, NSError *error){
            if (failure)
                NSLog(@"%@",error.localizedDescription);
        }];

您可以忽略我在其中设置acceptableContentTypes的那一行.

You can neglect the line in which i am setting the acceptableContentTypes.

希望这会有所帮助.

这篇关于在Objective-C中使用Afnetworking的发布方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆