我已经使用 htmlunit 一段时间了。现在我正在尝试向它引入超时功能。
它的工作方式如下:
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
//To disable throwing exception for script errors
webClient.setThrowExceptionOnScriptError(false);
//To disable java scripts
webClient.setJavaScriptEnabled(false);
//To disable the loading of CSS
webClient.setCssEnabled(false);
int timeout = 300;
// Add timeout for ETA
webClient.setTimeout(timeout);
try{
webClient.setUseInsecureSSL(true);
}catch(GeneralSecurityException e){
log.info("General Security Exception occured");
log.error("",e);
}
HtmlPage loginPage = (HtmlPage) webClient.getPage("myurl");
如果我减少超时,它会给我一个ConnectionTimeOutException
. 但是现在如果我更改设置顺序setTimeout
并且setUseInsecureSSL
它不起作用。我想说的是下面的代码不会让我连接超时。
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
//To disable throwing exception for script errors
webClient.setThrowExceptionOnScriptError(false);
//To disable java scripts
webClient.setJavaScriptEnabled(false);
//To disable the loading of CSS
webClient.setCssEnabled(false);
try{
webClient.setUseInsecureSSL(true);
}catch(GeneralSecurityException e){
log.info("General Security Exception occured");
log.error("",e);
}
//Setting it after setting "setUseInsecureSSL"
int timeout = 300;
// Add timeout for ETA
webClient.setTimeout(timeout);
谁能解释一下这是什么原因??
设置属性的顺序重要吗?