gpt4 book ai didi

nsurlconnection - RestKit奇怪地处理用户名和密码

转载 作者:行者123 更新时间:2023-12-04 07:13:13 28 4
gpt4 key购买 nike

我基本上将RestKit与RKClient一起使用,并执行get请求。我的系统使用用户名/密码/帐户来认证用户。它只是用于用户名/密码的httpbasic,而帐户只是一个子域。

我的问题是,如果执行以下操作:


使用正确的信息登录(然后下载该应用程序的所有数据)
重置数据(这将删除我所有的核心数据对象,并且还将共享RKClient的用户名和密码设置为空白)
输入错误的用户名/密码,但使用正确的帐户,然后它将下载数据,就好像它们是正确的一样。


我在设置用户名和密码之前和之后放置了puts,可以看到它被更改为错误的数据。并且我将缓存设置为RKRequestCachePolicyNone(在共享客户端和RKRequest实例上)。

返回的请求说它没有从缓存中拉出。当我尝试使用curl在终端中复制问题时,我得到了正确的响应(即我无法使用错误的用户名密码来获取数据)。

那么,为什么/如何使RestKit获得适当的响应?它击中服务器并获得200响应。

示例代码:

- (void)startDownload {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSLog(@"username and password before (%@,%@)",[RKClient sharedClient].username,[RKClient sharedClient].password);
[RKClient sharedClient].username = self.login;
[RKClient sharedClient].password = self.password;

NSLog(@"username and password after (%@,%@)",[RKClient sharedClient].username,[RKClient sharedClient].password);

NSString *base = [NSString stringWithFormat:@"http://%@.%@api",self.accountName,[defaults stringForKey:@"myURL"]];

[[RKClient sharedClient] setBaseURL:base];
[[RKClient sharedClient] setAuthenticationType:RKRequestAuthenticationTypeHTTPBasic];

[[RKClient sharedClient] setCachePolicy:RKRequestCachePolicyNone];

RKRequest *request = [[RKClient sharedClient] get:@"/verify.json" delegate:self];

[request setCachePolicy:RKRequestCachePolicyNone];
}


更新资料

我还注意到,如果我在首次登录时输入了错误的密码,它会作为失败返回。如果然后我更正密码,此后它总是会失败。

最佳答案

显然Restkit存储某种cookie进行身份验证。
就我而言,只要用户名保持不变,我就可以注销并使用错误的密码重新登录。

就我而言,我可以通过以下方法解决问题:

NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in cookieStorage.cookies)
{
[cookieStorage deleteCookie:cookie];
}


其中摆脱了所有存储的cookie。希望这也能解决您的问题。

关于nsurlconnection - RestKit奇怪地处理用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10924973/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com