美文网首页AFNetworking
AFNetworking “Post” 请求的坑

AFNetworking “Post” 请求的坑

作者: onavo | 来源:发表于2015-09-18 10:37 被阅读266次
    • (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);
      

      }];
      }

    相关文章

      网友评论

        本文标题:AFNetworking “Post” 请求的坑

        本文链接:https://www.haomeiwen.com/subject/pqmbcttx.html