I am trying to upload picture to server, via af 2.0 multipart request, but it seems body is always null. Here is a snapshot from code:
[self POST:path parame
You try this code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *strURL = @"http://YOUR_IP:YOUR_PORT/YOUR_PATH/..";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFJSONRequestSerializer *serializerRequest = [AFJSONRequestSerializer serializer];
[serializerRequest setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
AFJSONResponseSerializer *serializerResponse = [AFJSONResponseSerializer serializer];
serializerResponse.readingOptions = NSJSONReadingAllowFragments;
serializerResponse.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
manager.requestSerializer = serializerRequest;
manager.responseSerializer = serializerResponse;
UIImage *image = [UIImage imageNamed:@"image.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
NSDictionary *parameters = @{@"name":@"xxxx",
@"surname":@"xxxx",
};
[manager POST:strURL parameters:parameters constructingBodyWithBlock:^(id formData) {
[formData appendPartWithFormData:imageData name:@"photo"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@""%@,operation.responseString);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@""%@,operation.responseString);
}];
}