Usando a autenticação básica AFNetworking e HTTP
O código a seguir se conecta com êxito à minha API do Ruby on Rails e retorna o JSON usando o AFNetworking. O que preciso fazer para editar isso para passar um nome de usuário e senha para que minha API possa usar a Autenticação Básica HTTP?
Eu li a documentação deles, mas sou novo no Objective-C e AFNetworking e atualmente não faz sentido.
NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:3000/tasks.json"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request
, NSHTTPURLResponse *response
, id JSON) {
self.tasks = [JSON objectForKey:@"results"];
[self.activityIndicatorView stopAnimating];
[self.tableView setHidden:NO];
[self.tableView reloadData];
NSLog(@"JSON");
} failure:^(NSURLRequest *request
, NSHTTPURLResponse *response
, NSError *error
, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];