Is it possible to use HTTPS proxy in HTMLunit?

2019-05-01 19:54发布

问题:

I am new in HTMLunit and trying to set HTTPS proxy for HTMLunit. I tried to use https:// just before the HOST IP, but I got Exception.

Anyone can help me to solve this issue?


Update: My Code is:

 WebClient webClient = new  WebClient(BrowserVersion.FIREFOX_3_6,"https://199.127.100.13", 11888);

Update 2: I asked the developer team, The said that it is a bug in the framework. They will fix it.

回答1:

You should not be putting http:// or https:// behind the ip address of the proxy server.

If your http proxy server supports https then htmlunit would automatically use it. Here is an example of how to use proxy with htmlunit

For HTTP proxy

                ProxyConfig pc = new ProxyConfig();
                pc.setSocksProxy(false); //Set to false if it is a http server
                pc.setProxyHost("192.168.1.200"); //your proxy IP
                pc.setProxyPort(proxyPort);
                webClient.getOptions().setProxyConfig(pc);

and of course if you are using socks proxy than set the setSocksProxy to true.