0

我想使用 restkit putobject 发送 put 请求并从服务器接收响应为 200 和字符串,但服务器给我 400 并说没有接收正文。请求是请求:https ://myserver.com/api/v1/f1/ /update body = "somevalue" 响应是 200 "somevalue"

为此,我有 restkit 实施请求https://myserver.com/api/v1 path f1//update

这是代码

RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[ModelUpdate class]];
 [responseMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"status"]];

RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:responseMapping
                                             method:RKRequestMethodPUT
                                        pathPattern:path
                                            keyPath:nil
                                        statusCodes:[NSIndexSet indexSetWithIndex:200]];
*objectPath=path;
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[responseMapping inverseMapping]   objectClass:[ModelUpdate class] rootKeyPath:nil method:RKRequestMethodAny];

[rkObjectManager addResponseDescriptor:responseDescriptor];
[rkObjectManager addRequestDescriptor:requestDescriptor];
rkObjectManager.requestSerializationMIMEType = RKMIMETypeJSON;
[rkObjectManager putObject:someObj path:path parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

    id updateField = mappingResult.array;
    [sDFWebInterface->m_DFWebInterfaceData receiveResponse:updateField forRequestNo:requestNo error:nil];
    NSLog(@"Success");

} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Error from server in Put Request");
    [sDFWebInterface HandleServerAPIError:requestNo :error];
}];
  /////Modelupdate class
 @interface ModelUpdate : NSObject
 @property(nonatomic,strong)NSString* status;// : 

  @end
4

1 回答 1

0

您的请求描述符指定objectClass:[ModelUpdate class],因此仅当您提供类对象时才会使用它ModelUpdate

someobj basically a string object someobj="new value"与规范不匹配,因此不会处理该请求。您应该会在日志中看到关于此的错误。

If you just want to send a simple string and get a simple string in the response then you don't really need RestKit. If you want to process the string in and out of a ModelUpdate then you need to supply an appropriate instance.

于 2015-11-25T17:47:12.213 回答