【问题标题】:Forming Multi-part request through RestKit通过 RestKit 形成多部分请求
【发布时间】:2015-05-06 08:19:21
【问题描述】:

这是我将多部分数据发布到服务器的代码。我观察到请求中只包含图像数据,而不是文章对象。请让我知道过去是否有人成功地完成了这些工作。提前致谢。

 RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromArray:@[@"title", @"author", @"body"]];

RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping 
                                    objectClass:[Article class] rootKeyPath:@"article" method:RKRequestMethodAny];

[manager addRequestDescriptor:requestDescriptor];

Article *article = [Article new];
article.title = @"Introduction to RestKit";
article.body = @"This is some text.";
article.author = @"Blake";

NSMutableURLRequest *request = [objectManager multipartFormRequestWithObject:article
                                                                      method:RKRequestMethodPOST
                                                                        path:path
                                                                  parameters:nil
                                                   constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

                                                       [formData appendPartWithFileData:imageData
                                                                                   name:imageInfo
                                                                               fileName:imageName
                                                                               mimeType:@"image/jpeg"];

                                                   }];

RKObjectRequestOperation *operation1 = [objectManager objectRequestOperationWithRequest:request
                                                                               success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{

    // Process data
    NSLog(@"success");

} failure:^(RKObjectRequestOperation *operation, NSError *error) {

    // An error occurred
    NSLog(@"error");

}];

【问题讨论】:

    标签: objective-c afnetworking restkit multipartform-data


    【解决方案1】:

    使用 appendPartWithHeaders 解决了这个问题。 Source。 让我知道是否有人需要更仔细地查看实施。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2021-03-08
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      相关资源
      最近更新 更多