【问题标题】:RestKit: How to handle empty response.body?RestKit:如何处理空的 response.body?
【发布时间】:2014-02-16 11:35:59
【问题描述】:

我通过 POST 请求某些内容,而服务器只发送状态码 200,内容长度为 0。我该如何处理?我不允许添加没有映射的 RKResponseDescriptor,也不允许添加 RKResponseDescriptor。

【问题讨论】:

  • 非常相似的问题在这里有相似的答案:stackoverflow.com/questions/21830144/…我的回答也适用于当前问题:) 如果响应为空,也许你应该直接使用AFNetworking,因为不需要映射。跨度>

标签: ios objective-c null restkit restkit-0.20


【解决方案1】:

啊,我刚刚发现,你可以为 NSNull 类创建一个映射。这似乎行得通。代码如下:

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

        [restObjectManager addResponseDescriptor:response];
    }

请告诉我这是否正确。

【讨论】:

  • 这也对我有用,但由于服务器返回空的 text/plain 响应,我不得不为这种 mimetype 注册一个序列化程序,如下所示:[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/plain"]; in @987654323 @。由于答案为空,RKNSJSONSerialization 工作正常。
猜你喜欢
  • 1970-01-01
  • 2021-12-25
  • 2021-03-04
  • 2012-09-12
  • 2021-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多