-
(void)callLoginAPI
{
// 数据加密
CRSA *rsa = [CRSA shareInstance];
_accountEncrypt = [rsa encryptByRsa:self.accountTextField.text];
_passwordEncrypt = [rsa encryptByRsa:self.passwordTextField.text];// 网络请求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer]; // 重要的设置
// 请求参数
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setValue:_accountEncrypt forKey:@"account"];
[params setValue:_passwordEncrypt forKey:@"password"];[manager POST:BaseURLString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//返回数据转换(重要) NSString *jsonString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSLog(@"------ JSON: ----- %@", jsonString); // UIStoryboard *homePageStoryboard = [UIStoryboard storyboardWithName:@"YXWHomePageViewControllerStoryboard" bundle:nil]; YXWHomePageViewController *hvc = [homePageStoryboard instantiateInitialViewController]; [self.navigationController pushViewController:hvc animated:YES]; [self alertStatus:@"Login success" title:@"Congrats"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self alertStatus:@"Please enter both Username and Password" title:@"Login Failed !"]; NSLog(@"------- Error ---------: %@", error);
}];
}
网友评论