Why is HTMLunit not working on this https webpage?

I am trying to learn more about HTMLunit and do some tests at the moment. I am trying to get basic information such as page name and text from this site:

https: //....com (remote full URL, the important part is https)

The code I use is what works fine on other sites:

final WebClient webClient = new WebClient(); final HtmlPage page; page = (HtmlPage)webClient.getPage("https://medeczane.sgk.gov.tr/eczane/login.jsp"); System.out.println(page.getTitleText()); System.out.println(page.asText()); 

Why can't I get this basic information? If this is related to security measures, what are the features and can I get around them? Thanks.

Edit: Hmm, the code stops working after webclient.getpage () ;, test2 is not written. Therefore, I cannot check if the page is null or not.

  final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_2); final HtmlPage page; System.out.println("test1"); try { page = (HtmlPage)webClient.getPage("https://medeczane.sgk.gov.tr/eczane/login.jsp"); System.out.println("test2"); 
+4
source share
2 answers

I solved this by adding this line of code:

 webClient.setUseInsecureSSL(true); 

which is an outdated way to disable secure SSL. In the current version of HtmlUnit you should do:

 webClient.getOptions().setUseInsecureSSL(true); 
+10
source

I think this is an authentication problem. If I go to this page in Firefox, I get a login window.

Try

webClient.setAuthentication(realm,username,password);

before calling getPage ()

+1
source

Source: https://habr.com/ru/post/1344059/


All Articles