1
我正在用htmlunit測試論壇phpbb3。我在自動添加論壇phpbb主題中的消息時遇到了問題。我需要發佈隱藏的輸入:form_token和creation_time。 我怎樣才能得到它?在phpbb3中獲取form_token和time_creation
final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_7);
HtmlPage page = webClient.getPage(URL);
// get input "username"
final HtmlElement user_name = page.getElementsByName("username").get(0);
//enter of value
user_name.type(par[0]);
//get input "password"
final HtmlElement password = page.getElementsByName("password").get(0);
//enter of value
password.type(par[1]);
// get button 'login' and click
final HtmlSubmitInput submit_button = page.getElementByName("login");
page = submit_button.click();
//Go to the page of adding message
page=page.getAnchorByText("Your first forum").click();
page=page.getAnchorByText("Welcome to phpBB3").click();
page=page.getAnchorByHref("./posting.php?mode=reply&f=2&t=1").click();
//get textarea
final HtmlTextArea myMessage=page.getElementByName("message");
/* HtmlInput form_token=page.getElementByName("form_token");
form_token.setAttribute("value", "0");
HtmlInput creation_time=page.getElementByName("creation_time");
creation_time.setAttribute("value", "0");
*/
//enter the valye
myMessage.type("myText");
//get the button 'Submit' and click
final HtmlElement submit_post = page.getElementByName("post");
page=submit_post.click();
//Check that my text is on the page
if (page.asText().contains("myText") {
System.out.println("Yes");
}
else System.out.println("No");
但是在此操作之後,頁面上沒有新消息。據我所知,服務器檢查隱藏字段form_token和creation_time。如何獲得正確的字段值?或者你知道解決問題的其他方式?
見下文,請 – 2012-04-24 09:39:51