Restkit Basic Auth with http code 405



Im使用以下代码到接口以基本的http身份验证登录。

  RKRequest *loginRequest = [[RKRequest alloc] initWithURL:URL];
  loginRequest.timeoutInterval = REST_LOGIN_TIMEOUT;
    loginRequest.username = username;
    loginRequest.password = password;
    loginRequest.authenticationType = RKRequestAuthenticationTypeHTTPBasic;
    loginRequest.method = RKRequestMethodPOST;
    loginRequest.onDidLoadResponse = ^(RKResponse *response) {
        // blabla
    }
    ....sending request...

我第一次登录时,它就可以工作了。但是,如果我再次执行相同的请求,则会收到HTTP状态代码405。当我重新启动我的应用程序时,下一个请求再次工作。所以我认为它会自动保存一些数据,例如会话令牌或内部的东西。如何重置?有什么提示吗?

它确实会自动存储来自响应的任何cookie(包括会话cookie)。要清除此问题,请使用以下命令:

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

当然,您可以先检查 cookie,看看是否要删除它们。

相关内容

最新更新