以下代码成功连接到我的Ruby on Rails API并使用AFNetworking返回JSON.我需要做什么来编辑它以传递用户名和密码,以便我的API可以使用HTTP基本身份验证?
我已经阅读了他们的文档,但我是Objective-C和AFNetworking的新手,目前还没有意义.
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];
Run Code Online (Sandbox Code Playgroud)