How do I use basic auth with RestKit's getObject?

主宰稳场 提交于 2019-12-31 16:46:19

问题


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;

回答1:


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];

As MonkeyBonkey points out in the comments, you may need to force the authentication using a flag:

[RKObjectManager sharedManager].client.forceBasicAuthentication = YES;


来源:https://stackoverflow.com/questions/7455269/how-do-i-use-basic-auth-with-restkits-getobject

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!