4

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

https://....com (removed the full url, important part is that it is https)

The code I use is this, which is working fine on other websites:

 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 it is because of security measures, what are the specifics and can I bypass them ? Thanks.

Edit:Hmm the code stops working after webclient.getpage(); , test2 is not written. So I can not check if 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");
Tunca Ersoy
  • 339
  • 1
  • 4
  • 18
  • What happens when you run it? Is "page" null? – DaveH Mar 17 '11 at 08:20
  • If "test2" is not being written it seems likely that an exception is being thrown by getWebPage - can you see what it is in your catch block? – DaveH Mar 17 '11 at 09:11

2 Answers2

12

I solved this by adding this line of code:

webClient.setUseInsecureSSL(true);

which is deprecated way of disabling secure SSL. In current HtmlUnit version you have to do:

webClient.getOptions().setUseInsecureSSL(true);
szymond
  • 1,311
  • 2
  • 19
  • 41
Tunca Ersoy
  • 339
  • 1
  • 4
  • 18
1

I think that this is an authentication problem - If I go tho that page in Firefox I get a login box.

Try

webClient.setAuthentication(realm,username,password);

before the call the getPage()

DaveH
  • 7,187
  • 5
  • 32
  • 53
  • Writing a captcha is needed to login, so i think this will not work. Is there any way to transfer session information from a browser to my htmlunit program ? So that I can login from a browser and get automatically logged in with htmlunit also. – Tunca Ersoy Mar 17 '11 at 08:35