3

I request something with POST, and the server just sends status-code 200 with a content-length of 0 back. How can I handle this? I'm not allowed to add a RKResponseDescriptor without mapping, nor not add the RKResponseDescriptor.

Wez Sie Tato
  • 1,186
  • 12
  • 33
Nick
  • 2,662
  • 2
  • 25
  • 48
  • Very similar question here with similar answers: http://stackoverflow.com/questions/21830144/ios-and-restkit-how-to-get-a-text-html-response-right/43682106#43682106 My answer also applies to current question :) If response is empty, maybe you should use `AFNetworking` directly instead as there's no mapping needed. – GabLeRoux Apr 28 '17 at 14:21

1 Answers1

12

Ah, I just found out, you can create a mapping for the NSNull class. That seems to work. Here's the code:

    {
        RKObjectMapping* responseMapping = [RKObjectMapping mappingForClass:[NSNull class]];
        RKResponseDescriptor* response =
        [RKResponseDescriptor responseDescriptorWithMapping:responseMapping
                                                     method:RKRequestMethodAny
                                                pathPattern:@"entry/sync"
                                                    keyPath:nil
                                                statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

        [restObjectManager addResponseDescriptor:response];
    }

Please tell me if this is the right way.

Nick
  • 2,662
  • 2
  • 25
  • 48
  • This also worked for me, but since server was returning empty **text/plain** response, I had to register a serializer for this mimetype like this: `[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/plain"];` in `AppDeletegate.m`. Since answer is empty, `RKNSJSONSerialization` works just fine. – GabLeRoux May 04 '17 at 13:34