Search code examples
iosrestkitrestkit-0.20restkit-0.24.x

server is not receiving body object from webservice call of restkit


I want to send put request using restkit putobject and receive the response as 200 and string from the server, but server is giving me 400 and saying not receiving body. Request is request: https://myserver.com/api/v1/f1//update body = "somevalue" Response is 200 "somevalue"

for this i am having restkit implment request https://myserver.com/api/v1 path f1//update

here is the code

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

Solution

  • Your request descriptor specifies objectClass:[ModelUpdate class], so it will only be used when you supply an object of class ModelUpdate.

    someobj basically a string object someobj="new value" doesn't match the spec so the request won't be processed. You should see an error about that in the log.

    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.