在 iOS 的 RestKit 中执行 postObject 时忽略响应
我正在使用 RestKit 连接到我们的 WCF 数据服务。
由于响应映射问题,我在使用 RKObjectManager 的 postObject 函数添加实体时遇到问题。
添加实体时,WCF 数据服务返回 201 状态代码和新添加的实体(作为响应)。
是否可以忽略响应并仅使用返回的状态代码来检查添加是否成功?
波努
I am using RestKit for connecting to our WCF Data Services.
I am having issues with adding an entity using RKObjectManager's postObject function due to response mapping issues.
When an entity is added, WCF Data Services returns a 201 status code and the newly added entity(as response).
Is it possible to ignore the response and just use the status code returned to check if the add succeeded?
Ponnu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么要忽略从服务器返回的新添加的实体?映射该结果对于保持本地表示与服务器表示的同步很有用。服务器可能已经覆盖了对象的某些字段(例如对象 ID),并且您想要跟踪它。
如果出现映射错误,可能是因为对 POST 操作的响应返回对象的表示形式,该表示形式与 GET 返回的对象表示形式不同。
您是否尝试过使用:
- (RKObjectLoader*)postObject:(id)object mapResponseWith:(RKObjectMapping*)objectMapping delegate:(id)delegate
代替并指定更合适的映射返回的数据?
Why would you want to ignore the newly added entity returned from the server? Mapping that result is useful to keep in sync your local representation with the server's one. The server may have overwritten some field of your object like the object id and you want to keep track of it.
If you have mapping error it's probably because the response to the POST action returns a representation of your object which differs from the one returned with a GET.
Have you tried using:
- (RKObjectLoader*)postObject:(id<NSObject>)object mapResponseWith:(RKObjectMapping*)objectMapping delegate:(id<RKObjectLoaderDelegate>)delegate
instead and specify a more suitable mapping for the data returned?
这里的问题可能是更改 REST 服务,因此一个简单的解决方案是在 postObject 调用某个资源路径的情况下忽略对 didFailWithError 的回调。
The problem here can be to alter the REST service, so instead a simple solution would be to ignore the callback to didFailWithError in case of postObject calls to a certain resource path.
创建一个简单的 RKObjectMapping,它不关心响应中的任何参数。
Create a trivial RKObjectMapping that does not care about any parameters in response.