我想使用 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