以下代码成功连接到我的Ruby on Rails API并使用AFNetworking返回JSON。我需要做什么来编辑它以传递用户名和密码,以便我的API可以使用HTTP基本身份验证?
我已经阅读了他们的文档,但我对Objective-C和AFNetworking都很陌生,目前还不太理解。
我已经阅读了他们的文档,但我对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];
- (void)setUsername:(NSString *)username andPassword:(NSString *)password;
,我认为您需要从末尾删除那个分号。 - GeneralMike