AFN post请求

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

manager.requestSerializer = [AFHTTPRequestSerializer serializer];

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

manager.requestSerializer.timeoutInterval = 10;

[manager POST:[NSString stringWithFormat:@"%@/login/validatePhone",MGHZSUrl] parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

NSDictionary *dictArray = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:nil];

MGLog(@"POST成功:%@",dictArray);

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

MGLog(@"POST失败原因:%@",error);

NSData *data = error.userInfo[@"com.alamofire.serialization.response.error.data"];

NSString *String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

MGLog(@"失败原因:%@",String);

}];

你可能感兴趣的:(AFN post请求)