ASIFormDataRequest 登录

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: [NSURL URLWithString: @"http://oatest.tpyzq.com/names.nsf?Login"]];
request.shouldRedirect = NO;

[request addPostValue: _usernameTF.text forKey: USERNAME];
[request addPostValue: _passwordTF.text forKey: PASSWORD];

[request startSynchronous];

NSError *error = [request error];
if (!error)
{
//如果登录成功
if ([[request responseString] length]==0 && [[request responseCookies] count] != 0)
{

[[NSUserDefaults standardUserDefaults] setBool: _checkBoxView.selected forKey: OA_AUTO_LOGIN];
if (_checkBoxView.selected)
{

NSMutableDictionary *newCredentials = [NSMutableDictionary dictionary];

[newCredentials setObject: _usernameTF.text forKey: (NSString *)kCFHTTPAuthenticationUsername];
[newCredentials setObject: _passwordTF.text forKey: (NSString *)kCFHTTPAuthenticationPassword];

[request saveCredentialsToKeychain: newCredentials];
}

[self.navigationController popViewControllerAnimated: YES];

return;
}
}

posted @ 2014-02-28 12:05  墨禾米说  阅读(337)  评论(0编辑  收藏  举报