我正在尝试在没有映射的情况下将对象发送到服务器(PUT 请求),因为我已经从服务器获得了我需要的一切。即使服务器已成功创建对象,回调也会直接失败。
这是我正在做的一个例子:
- (void) PUTsuccess:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure
{
RKObjectManager *objectManager = [YSManager objectManager];
[objectManager putObject:self path:[kPutPath stringByAppendingString:self.id] parameters:kAPIDefaultParameters success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"operation.HTTPRequestOperation.request.HTTPBody: %@", [[NSString alloc] initWithData:operation.HTTPRequestOperation.request.HTTPBody encoding:NSUTF8StringEncoding]);
if (success) {
success(operation, mappingResult);
}
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failure! Error: %@", error.localizedDescription);
if (failure) {
failure(operation, error);
}
}];
}
服务器响应是 201 创建的,我可以在服务器中找到我的对象,所以这一切都很好,但是,回调直接触发失败,因为它正在尝试映射我的对象,失败回调中的错误是:
Error: No response descriptors match the response loaded.
非常感谢,任何建议将不胜感激!
更新 1 现在添加了字典映射:
RKObjectMapping *idMapping = [RKObjectMapping requestMapping];
[idMapping addAttributeMappingsFromArray:@[]];
RKResponseDescriptor *responseDescriptorID = [RKResponseDescriptor responseDescriptorWithMapping:idMapping
pathPattern:[kRequestPath stringByAppendingString:@":code"]
keyPath:@"objects"
statusCodes:statusCodes];