【问题标题】:Post path must match exactly with RKResponseDescriptor pathPattern发布路径必须与 RKResponseDescriptor pathPattern 完全匹配
【发布时间】:2014-04-21 18:35:21
【问题描述】:

所以我用于更新对象的当前服务遵循以下 URL 的格式

http://www.baseurl.com/servicemethodAddObject/transactionId?clientTime=clientTime

这就是我放在那里的代码。大概。

[objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:eventResponseMapping method:RKRequestMethodGET pathPattern:@"/GetStuff" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];

// I'd want to add items to the URL but the parameters parameter only goes in to the post body, If I add objects to the path @"?GetStuff/?parm=Stuff&parm2=stuff2" then the response will not be mapped properly
[objectManager postObject:object path:@"/GetStuff" parameters:parms success:nil failure:nil];

似乎 RestKit 要求用于发布对象的路径和用于创建 RKDescriptor 的 pathPattern 必须完全匹配。有没有办法让restKit进行忽略其对象映射的url参数的比较?

这是正确的做法吗?在 URL 中发布对象并添加项目。

【问题讨论】:

    标签: ios json url restkit


    【解决方案1】:

    您可以构建路径以添加参数。使用 pathPattern:@"/GetStuff" 将匹配已构建的路径,例如:

    @"/GetStuff?parm=Stuff&parm2=stuff2"
    

    (如果添加或删除不在路径模式中的 / 字符,您将遇到问题)

    【讨论】:

    • 我必须添加和删除描述符,因为 url 总是在变化,这看起来像是一个巨大的 hack。是否可以让路径模式识别某些项目将是动态的?我认为您不能在路径模式中添加正则表达式,但这会起作用。我在rest kit github上发布,他们的解决方案是在发布时不添加url参数。
    • 理想情况下你不会使用查询参数,不。路径模式可以带参数,查看规范 github.com/NimbusKit/sockit 但这不是用于查询参数,而是用于路径段
    【解决方案2】:

    https://github.com/RestKit/RestKit/issues/1877

    显然解决办法是不这样做。

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 2020-09-01
      • 1970-01-01
      • 2020-06-01
      相关资源
      最近更新 更多