Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 一旦HTMLUnit忽略form.setActionAttribute和fom.setAttribute,将请求发布到正确的URL_Java_Forms_Httpwebrequest_Html Parsing_Htmlunit - Fatal编程技术网

Java 一旦HTMLUnit忽略form.setActionAttribute和fom.setAttribute,将请求发布到正确的URL

Java 一旦HTMLUnit忽略form.setActionAttribute和fom.setAttribute,将请求发布到正确的URL,java,forms,httpwebrequest,html-parsing,htmlunit,Java,Forms,Httpwebrequest,Html Parsing,Htmlunit,我正试图使用HTMLUnit提交表单,但似乎一旦http帖子进入同一页面,表单的action属性就会被忽略。 我正在获取此URL上的表单: 在这个URL的源代码中,我们可以发现action属性被设置为这个URL: 但是HTMLUnit总是发布到第一个URL 我正在使用fiddler通过一个真正的web浏览器和HTMLUnit分析请求,并比较这两个HTTP POST很容易看出HTMLUnit正在发布到同一个站点,即提到的第一个URL 我需要将HTMLUnit POST发送到第二个URL 如果有

我正试图使用
HTMLUnit
提交表单,但似乎一旦http帖子进入同一页面,表单的action属性就会被忽略。 我正在获取此URL上的表单:

在这个URL的源代码中,我们可以发现action属性被设置为这个URL:

但是
HTMLUnit
总是发布到第一个URL

我正在使用fiddler通过一个真正的web浏览器和
HTMLUnit
分析请求,并比较这两个
HTTP POST
很容易看出
HTMLUnit
正在发布到同一个站点,即提到的第一个URL

我需要将
HTMLUnit POST
发送到第二个URL

如果有人能帮助我,我将不胜感激。

问题解决了

而不是使用:

HtmlPage page2 = button.click();
我用过:

button.click().getWebResponse().getContentAsString();

我将使用与以下内容类似的东西

// Enter your username in feild
searchForm.getInputByName("Username").setValueAttribute(schoolID);

//Submit the form and get the result page       
HtmlPage pageResult = (HtmlPage) searchForm.getInputByValue("Search").click();

//Page results in raw html source code  
String html = pageResult.asXml();

    /*
    * filter source code if needed to collect desired data
    */

//login via another server url
page = (HtmlPage) webClient.getPage("https://"+url);
HtmlForm LoginForm = page.getFormByName("Form1");

// login to web portal
LoginForm.getInputByName("txtUserName").setValueAttribute(username);
LoginForm.getInputByName("txtPassword").setValueAttribute(password);

//Submit the form and get the result page
HtmlPage pageResult = (HtmlPage) LoginForm.getInputByName("btnLogin").click();
注意:此htmlUnit代码与htmlUnit 2.15 API兼容