用于上传多部分表单的AFNetworking 2.0方法是什么,即使用AFHTTPSessionManager
或AFHTTPRequestOperationManager
以下是一些AFNetworking< 2.0代码:
[[ASAPIClient sharedClient] enqueueHTTPRequestOperation:[[ASAPIClient sharedClient] HTTPRequestOperationWithRequest:[[ASAPIClient sharedClient] multipartFormRequestWithMethod:@"POST" path:@"/some/url" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
if(_selectedPhoto.image)
{
NSData *imageData = UIImageJPEGRepresentation([_selectedPhoto image], 0.5);
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}
}] success:^(AFHTTPRequestOperation *operation, id responseObject) {
if([[responseObject objectForKey:@"result"]isKindOfClass:[NSDictionary class]] )
{
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}]];
答案 0 :(得分:3)
ASAPIManager
是AFHTTPRequestOperationManager
[[ASAPIManager sharedManager] POST:@"/some/url" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
if(_profileImageView.image){
[formData appendPartWithFileData:UIImageJPEGRepresentation(_profileImageView.image, 0.5) name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];