我需要這裏的優點來啓發我的代碼有什麼問題。我正在嘗試從2.x遷移到3.x,並且我患有偏頭痛。AFNetworking 3.0發佈問題
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSDictionary *parameters = @{@"email": email, @"password": password};
[manager POST:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData
options:0
error:nil];
if ([[json objectForKey:@"success"] intValue] != 1) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"" message:self.error_login delegate:nil cancelButtonTitle:self.continueButton otherButtonTitles:nil];
[MBProgressHUD hideHUDForView:self.view animated:YES];
[alert show];
} else {
[MBProgressHUD hideHUDForView:self.view animated:YES];
AccountViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"account"];
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
[viewControllers removeLastObject];
[viewControllers addObject:vc];
[[self navigationController] setViewControllers:viewControllers animated:NO];
}
} failure:^(NSURLSessionDataTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
服務器端一直顯示參數爲空。
任何指導,將不勝感激= d
設置參數的代碼對我來說看起來是正確的。你確定'email'和'password'中有值嗎? –
你可以打印這個結果'參數' –
簡單的解決方案使用像這樣... http://stackoverflow.com/questions/34561215/afnetworking-3-0-migration-how-to-post-with-headers-and -http-body/36299737#36299737 – Vvk