使用RestKit和RKObjectManager时如何添加一些默认参数? [英] How do I add some default parameters when using RestKit and RKObjectManager?
问题描述
我正在使用RestKit,RKObjectManager和服务器端设计身份验证。我需要在每个请求上发送我的身份验证令牌。有没有办法可以轻松地添加所有请求?
I'm using RestKit, RKObjectManager, and, server side, devise for authentication. I need to send my authentication token on every request. Is there a way I can easily add it for all requests?
目前,对于GETs,我正在做以下操作:
Currently, for GETs, I'm doing the following:
NSString *path = [NSString stringWithFormat:@"/%@/%i", [self pluralizedName], identifier];
path = [path stringByAppendingQueryParameters:[self appendAuthenticationToken:params]];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:path delegate:delegate];
这很好用。但是,对于PUT,我尝试了以下内容:
This works great. However, for PUTs, I tried the following:
[[RKObjectManager sharedManager] putObject:resource usingBlock:^(RKObjectLoader *loader) {
loader.delegate = delegate;
loader.params = [RKParams paramsWithDictionary:[self appendAuthenticationToken:params]];
}];
正确发送了我的身份验证令牌,但服务器没有收到我正在尝试更新的资源。有没有人知道这样做的正确方法?
This correctly sent my authentication token, but the server didn't receive the resource I was trying to update. Does anyone know the correct way of doing this?
推荐答案
在RestKit .2中,您将解决这个问题: >
In RestKit .2, you would address this issue as:
[[[RKObjectManager sharedManager] HTTPClient] setAuthorizationHeaderWithToken:self.user.token];
这篇关于使用RestKit和RKObjectManager时如何添加一些默认参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!