dpt62283 2015-10-02 12:01
浏览 93

无法在afnetworking中传递nsdictionary作为param?

I want to ns dictionary as param in afnetworking in post request but i am not able to send the nsdictionary php end i am unable to decode. here is my code

NSMutableDictionary *dict_hashtags=[[NSMutableDictionary alloc]init];

    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:[BASE_URL stringByAppendingString:ADD_POST]]];
    AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
    [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [requestSerializer setValue:api_key forHTTPHeaderField:@"Authorization"];
    manager.requestSerializer = requestSerializer;
    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];
    responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
    manager.responseSerializer = responseSerializer;
      NSString *font_size = [NSString stringWithFormat:@"%f", textSize];

    if([self.txt_hashtags.text length]>0)
    {
        NSLog(@"lenght is greater");
        dict_hashtags=[self getHashTags:self.txt_hashtags.text];


    }
    NSLog(@"HASHTAGS ARE %@",dict_hashtags);
    NSDictionary *parameters = @{@"title": postTitle, @"details" :postDescription,@"location":address,@"font_size":font_size,@"font_family":fontName,@"font_color":color_name,@"is_album":isAlbum,@"hash_tag":dict_hashtags};

    NSLog(@"PARAMS ARE %@",parameters);
    AFHTTPRequestOperation *op = [manager POST:[BASE_URL stringByAppendingString:ADD_POST] parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
                                  {
                                      //do not put image inside parameters dictionary as I did, but append it!
                                      if(userImageData!=nil)
                                      {
                                          [formData appendPartWithFileData:userImageData name:@"album_image" fileName:@"image0" mimeType:@"image/jpeg"];
                                      }

                                  }
                                       success:^(AFHTTPRequestOperation *operation, id responseObject)
                                  {


                                  }
                                       failure:^(AFHTTPRequestOperation *operation, NSError *error)

                                  {
                                      [self activityIndicator:@"hide"];
                                      NSLog(@"Error: %@ ***** %@", operation.responseString, error);
                                      UIAlertView *AlbumAlert =[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Album could not added.Try again" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                                      [AlbumAlert show];
                                  }];
    [op start];

My params are as follows:

PARAMS ARE {
    details = "Gggghh
";
    "font_color" = black;
    "font_family" = "Helvetica-Nue";
    "font_size" = "18.000000";
    "hash_tag" =     {
        "hash_tags" =         (
            ghygg
        );
    };
    "is_album" = no;
    location = "";
    title = ggg;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)