服务器未从 restkit 的 webservice 调用接收正文对象
server is not receiving body object from webservice call of restkit
我想使用 restkit putobject 发送放置请求并从服务器接收响应 200 和字符串,但服务器给我 400 并说没有收到正文。
要求是
请求:https://myserver.com/api/v1/f1//更新
正文 = "somevalue"
响应为 200
"somevalue"
为此,我正在使用 restkit 实现
请求 https://myserver.com/api/v1
路径 f1//更新
这是代码
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
您的请求描述符指定了 objectClass:[ModelUpdate class]
,因此它只会在您提供 class ModelUpdate
的对象时使用。
someobj basically a string object someobj="new value"
与规范不匹配,因此不会处理该请求。您应该会在日志中看到关于此的错误。
如果您只想发送一个简单的字符串并在响应中获得一个简单的字符串,那么您并不真的需要 RestKit。如果你想处理进出 ModelUpdate
的字符串,那么你需要提供一个合适的实例。
我想使用 restkit putobject 发送放置请求并从服务器接收响应 200 和字符串,但服务器给我 400 并说没有收到正文。 要求是 请求:https://myserver.com/api/v1/f1//更新 正文 = "somevalue" 响应为 200 "somevalue"
为此,我正在使用 restkit 实现 请求 https://myserver.com/api/v1 路径 f1//更新
这是代码
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
您的请求描述符指定了 objectClass:[ModelUpdate class]
,因此它只会在您提供 class ModelUpdate
的对象时使用。
someobj basically a string object someobj="new value"
与规范不匹配,因此不会处理该请求。您应该会在日志中看到关于此的错误。
如果您只想发送一个简单的字符串并在响应中获得一个简单的字符串,那么您并不真的需要 RestKit。如果你想处理进出 ModelUpdate
的字符串,那么你需要提供一个合适的实例。