请求auhtorization 401失败

时间:2016-04-01 11:51:22

标签: afnetworking-2

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSString *URLString = @"http://52.201.233.32:1337/login";
NSURL*url=[NSURL URLWithString:URLString];
NSDictionary *parameters = @{@"email":@"one_user@gmail.com", @"password":@"asdfasdf"};

NSMutableURLRequest*request=[[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:URLString parameters:parameters error:nil];

manager.responseSerializer=[AFHTTPResponseSerializer serializer];

[[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:URLString parameters:parameters error:nil];


NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
    NSLog(@"Error: %@", error);
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:ok];

    [self presentViewController:alertController animated:YES completion:nil]; 
} else {            
    NSArray *responseArray = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
    NSLog(@"%@ ----->%@", response, responseArray[0][@"email"]);
    self.fullarray = responseArray[0][@"email"];        }
}];
[dataTask resume];

0 个答案:

没有答案