Tried to use a session.
But the situation does not change; There are two links on the index.html; one is google (no restricted area) and the other is under the current directory which is the area where the basic auth is necessary. The page transition to google was successful now, but that to the restricted area is not.
Any hints would be appreciated!
Thank you very much!
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *urlString = @"https://test.com/test/";
//username and password value
NSString *username = @"test1";
NSString *password = @"test1";
//HTTP Basic Authentication
NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", username, password] ;
NSData *authenticationData = [authenticationString dataUsingEncoding:NSASCIIStringEncoding];
NSString *authenticationValue = [authenticationData base64Encoding];
//Set up your request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"GET"];
//[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"Basic %@", authenticationValue] forHTTPHeaderField:@"Authorization"];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (!error) {
NSLog(@"good!: %@", data); //[NSString stringWithFormat:@"ID %@", DevID];
NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", html);
NSURL *url = [NSURL URLWithString:urlString];
[self->_webView loadHTMLString:html baseURL:url];
}
}] resume];
}