我想制作一个注册表单,在这里我已经将所有UITextField数据都用字符串并使用post方法发送api,但我不知道如何使用所有数据在api上发送图像?
答案 0 :(得分:0)
尝试以下代码段
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL: [NSURL URLWithString:@"Your URL"]];
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"YourValue",@"ValueName",@"YourValue",@"ValueName", nil];
NSData *imageData = UIImagePNGRepresentation(img_Picture);
[manager POST:@"Your URL" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:@"logo" fileName:@"image.png" mimeType:@"image/png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure %@, %@", error, operation.responseString);
}];
其中参数包含所有文本字段的数据。
Logo是用于api编码的图像参数名称。