如何在RestKit的getObject中使用基本auth? [英] How do I use basic auth with RestKit's getObject?
本文介绍了如何在RestKit的getObject中使用基本auth?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下设置基本身份验证用户名和密码,但它似乎没有在请求中传递基本身份验证。
I tried the following to set the basic auth username and password, but it does not seem to be passing the basic auth in the request..
secureManager = [[RKObjectManager objectManagerWithBaseURL:@"http://localhost:3000"] retain];
secureManager.client.username = uname;
secureManager.client.password = pwd;
RKObjectLoader *loader = [svc getObject:user delegate:self];
loader.userData = [NSNumber numberWithInt:RequestLogin];
更新:发现我的问题,我需要添加以下代码段
UPDATE: found my problem, I needed to add the following snippet
secureManager.client.forceBasicAuthentication = YES;
推荐答案
您可以先获取基础RKClient的实例发出请求并设置用户名和密码,如下所示:
You can grab an instance of the underlying RKClient before you make your request and set the Username and Password like so:
// Set the Username and Password
[RKObjectManager sharedManager].client.username = @"username";
[RKObjectManager sharedManager].client.password = @"letmein";
// Make our Request
[[RKObjectManager sharedManager] getObject:user mapResponseWith:mapping delegate:self];
正如MonkeyBonkey在评论中指出的那样,您可能需要使用标志强制进行身份验证:
As MonkeyBonkey points out in the comments, you may need to force the authentication using a flag:
[RKObjectManager sharedManager].client.forceBasicAuthentication = YES;
这篇关于如何在RestKit的getObject中使用基本auth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文