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];