如何解决HTMLUNIT-向Ajax请求发送Cookie时出现问题
I,m使用HtmlUnit版本2.43。 当我单击按钮时,将调用函数javascript。该函数创建一个链接(新URL),该新页面需要Cookie(JSESSIONID),执行后,结果将显示在标签DIV中。 但是我尝试了所有事情,但无法做到这一点。 请有人帮我!
代码: WebClient客户端=新的WebClient(BrowserVersion.CHROME); WebClientOptions options = client.getOptions();
CookieManager cookieManager = client.getCookieManager();
cookieManager.setCookiesEnabled(true);
client.setCookieManager(cookieManager);
client.getOptions().setJavaScriptEnabled(true);
client.setAjaxController(new NicelyResynchronizingAjaxController());
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setCssEnabled(false);
HtmlTextInput inputCaptcha = paginaAfterConsultaIdentificadorCaptcha.querySelector("input[name='questionCL']");
inputCaptcha.setValueAttribute("gr5w4");
HtmlPage paginaInfLote = ((HtmlButtonInput) paginaAfterConsultaIdentificadorCaptcha.getElementById("botao_continuar")).click();
client.setJavaScriptTimeout(10000);
System.out.println(paginaInfLote.asXml());
<!-- I tried set to new cookie: -->
Iterator<Cookie> index = cookies4.iterator();
while (index.hasNext()) {
vSessionId = index.next().toString();
System.out.println(index.next());
break;
}
String vValueCookie = vSessionId.substring(11,vSessionId.indexOf(";"));
Date dt = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.DATE,1);
dt = c.getTime();
Cookie cookie = new Cookie("www.licitacoes-e.com.br","JSESSIONID",vValueCookie,"/",dt,false);
cookieManager.addCookie(cookie);
client.setCookieManager(cookieManager);
<!-- Fim set cookie -->
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。