ASIHTTPRequest用戶登陸:重複用戶登陸問題解決

使用ASIHTTPRequest來實現用戶登錄,但是無論如何登陸的用戶總是同一個

- (IBAction)signin:(id)sender

{……..

ASIFormDataRequest *request = [ASIFormDataRequestrequestWithURL:loginUrl];

[request setDelegate:self];

[request setRequestMethod:@"POST"];

[request setPostValue:username.textforKey:@"username"];

[request setPostValue:password.textforKey:@"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];


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章