Objective-C:如何使用类型键值的多维数组发送post请求

时间:2018-03-07 19:05:27

标签: ios objective-c rest http afnetworking

从目标(我们使用AFNetworking)编写的应用程序中,我需要发送一个POST请求,其中包含一个多维数组"键":"值&# 34;

我们以这种方式发送请求:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    manager.requestSerializer = [AFJSONRequestSerializer serializer];
                    [manager.requestSerializer setValue:@“application/json” forHTTPHeaderField:@“Accept”];
                    [manager.requestSerializer setValue:@“multipart/form-data” forHTTPHeaderField:@“Content-Type”];


                   [manager POST:url parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {


                       for (UIImage* image in photoArray) {

                           NSData *dataImage = UIImageJPEGRepresentation(image,1);


                            [formData appendPartWithFileData:dataImage name:randomString fileName:[NSString stringWithFormat:@“%@.jpeg”,randomString] mimeType:@“image/jpeg”];
                        }


                   } progress:^(NSProgress * _Nonnull uploadProgress) {



                   } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

                       NSLog(@“!!!!! %@“, responseObject);

                       if (success) {

                           [KVNProgress dismiss];
                            success(responseObject);

                       }


                   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                       NSLog(@“%@“, error.localizedFailureReason);
                        [KVNProgress showError];

                   }];

这样我们就形成了NSDictionary:

NSString*name = model.name;
NSString*lat = model.lat;
NSString*lon = model.lon;
NSDictionary* dic = [NSDictionary
dictionaryWithObjectsAndKeys:name,@"name",lat,@"lat",lon,@"lon", nil];
[addressArray addObject:dic];

以下是我们对Objective的看法 1

这是服务器收到的请求 2
而这里应该是什么 3

如何在Objective上构建一个对象,以便数据[地址]如3图片所示进入HTTP服务器?

0 个答案:

没有答案