AFHTTPRequestOperation

AFHTTPRequestOperation

什么是AFNetworking 2.0用于上传多部分表单(即AFHTTPSessionManagerAFHTTPRequestOperationManager)的方法

这是一些AFNetworking

[[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) {

    }]];

最佳答案

ASAPIManagerAFHTTPRequestOperationManager的子类

[[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) {

    }];

09-13 12:42