从目标(我们使用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的看法
这是服务器收到的请求
而这里应该是什么
如何在Objective上构建一个对象,以便数据[地址]如3图片所示进入HTTP服务器?