ASIHTTPRequest用户登陆:重复用户登陆问题解决

使用ASIHTTPRequest来实现用户登录,但是无论如何登陆的用户总是同一个

- (IBAction)signin:(id)sender

{……..

ASIFormDataRequest *request = [ASIFormDataRequestrequestWithURL:loginUrl];

[request setDelegate:self];

[request setRequestMethod:@"POST"];

[request setPostValue:username.text forKey:@"username"];

[request setPostValue:password.text forKey:@"password"];

[request startAsynchronous];

[request setDidFailSelector:@selector(requestLoginFailed:)];

[request setDidFinishSelector:@selector(requestLoginFinished:)];

}

实现登陆的Delegate

- (void)requestLoginFinished:(ASIHTTPRequest *)request

{

NSDictionary *loginResponse = [[request responseString] objectFromJSONString];

NSLog(@"login info->%@",loginResponse);

}

 

但是NSLog的结果总是同一用户,解决方式是,清除Cookie,ASIHTTPRequest登陆的模式和浏览器是相似的,会保存Cookie。所以需要在每次登陆前清理。但是在SignOut时清理是不行的。

[ASIHTTPRequestsetSessionCookies:nil];
作者:Buro#79xxd 出处:http://www.cnblogs.com/buro79xxd/ 文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/buro79xxd/p/2640130.html