问题
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