1
Я пытаюсь вызвать URL-адрес и вернуться к объекту json. Тем не менее, я не смог выяснить, где поставить базовую аутентификацию в операции AFNetworking. Я смог получить свой объект JSON с помощью POSTMAN следующим образом.Основная аутентификация с AFNetworking
Codesnippet работы AFNetworking:
NSString *string = @"MYURL";
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
int total_count = (int)[[responseObject valueForKey:@"total_count"] integerValue];
if (total_count > 0) {
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:total_count];
for (int i = 1; i <= total_count; i++) {
NSString *key = [NSString stringWithFormat:@"%i", i];
id object = [responseObject objectForKey:key];
[array addObject:object];
}
menuArray=array;
tableData = [NSArray arrayWithArray:array];
[categoryTableView reloadData];
}
else
{
NSLog(@"There is no internet connection!");
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// 4
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"There is no internet connection!"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
Вот POSTMAN, Вызов URL с Basic Authorization