使用ASIHTTPRequest來實現用戶登陸,可是不管如何登錄的用戶老是同一個瀏覽器
- (IBAction)signin:(id)senderide
{……..spa
ASIFormDataRequest *request = [ASIFormDataRequestrequestWithURL:loginUrl];orm
[request setDelegate:self];it
[request setRequestMethod:@"POST"];io
[request setPostValue:username.textforKey:@"username"];class
[request setPostValue:password.textforKey:@"password"];登錄
[request startAsynchronous];object
[request setDidFailSelector:@selector(requestLoginFailed:)];select
[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];