我第一次能够登录网站但是对于以后使用不同凭据的请求,HTMLUnit会提供200而不是302.
任何想法为什么我连续请求都没有得到302?我相信它是因为服务器正在发送:
Expires: Sun, 12 Jul 2015 01:24:57 GMT[\r][\n]"
2015-07-11 11:25:01,968 DEBUG [org.apache.http.wire:63][pool-6-thread-2] - << "Cache-Control: public, max-age=36000[\r][\n]"
作出回应。我该如何克服这个问题?
final WebClient webClient = new WebClient();
final HtmlPage page1 = webClient.getPage(Url);
final HtmlForm form = page1.getFormByName("form_name");
final HtmlSubmitInput button = form.getInputByValue("Sign In");
final HtmlTextInput user = form.getInputByName("username");
user.setValueAttribute("admin");
final HtmlPasswordInput pass = form.getInputByName("password");
pass.setValueAttribute("admin");
final HtmlPage page2 = button.click();
HtmlAnchor anchor = page2.getAnchorByText("logout");
anchor.click();
webClient.getCache().clear();
webClient.getCookieManager().clearCookies();
webClient.closeAllWindows();
我正在使用Liferay Tomcat的代码。