我尝试了以下设置基本的auth用户名和密码,但它似乎没有在请求中传递基本身份验证.
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];
secureManager.client.forceBasicAuthentication = YES;
解决方法
您可以在发出请求之前获取基础RKClient的实例,并设置用户名和密码,如下所示:
// 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在评论中指出的那样,您可能需要使用标志强制进行身份验证:
[RKObjectManager sharedManager].client.forceBasicAuthentication = YES;