How do I use basic auth with RestKit's getObject?
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开发者_如何学Go:@"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;
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;
精彩评论