我想使用restkit putobject发送put请求并从服务器接收响应为200和字符串,但是服务器给了我400并说不接收正文。 请求是 请求:https://myserver.com/api/v1/f1/ /更新 body =" somevalue" 回复是200 " someValue中"
为此我有restkit implment 请求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
答案 0 :(得分:0)
您的请求描述符指定objectClass:[ModelUpdate class]
,因此只有在提供类ModelUpdate
的对象时才会使用它。
someobj basically a string object someobj="new value"
与规范不匹配,因此请求无法处理。您应该在日志中看到有关该错误的错误。
如果您只想发送一个简单的字符串并在响应中获得一个简单的字符串,那么您并不需要RestKit。如果要处理进出ModelUpdate
的字符串,则需要提供适当的实例。