如何将基本身份验证与 RestKit 的 getObject 结合使用?
我尝试了以下方法来设置基本身份验证用户名和密码,但它似乎没有在请求中传递基本身份验证。
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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在发出请求之前获取底层 RKClient 的实例并设置用户名和密码,如下所示:
正如 MonkeyBonkey 在评论中指出的那样,您可能需要使用标志强制进行身份验证:
You can grab an instance of the underlying RKClient before you make your request and set the Username and Password like so:
As MonkeyBonkey points out in the comments, you may need to force the authentication using a flag: