Mike, first let me say I think you're doing a great job with HtmlUnit.
After creating a "sandbox" to test my problems outside of my normal
development environment, I determined that the real problem I am
experiencing using the "gump" build of commons-httpclient.jar is that text
input fileds set programatically using HtmlInput.setValueAttribute() are not
being received on the server end when the form is submitted. I verified
this with a servlet that extracts the request parameters. The parameters are
being received, but the values are empty.
I downloaded the latest version of commons-httpclient.jar
(commons-httpclient-20021204.zip) and the problem was solved.
However, both the "gump" and 20021204 versions do not seem to properly
handle WebResponse.getContentAsString() like the version included with
HtmlUnit-1.1-pre5.
My tests revealed the following results:
- pre5 creates a viewable HTML page containing the contents of page1.html as
expected.
- gump creates an empty file.
- 20021204 creates a file containing the word "null"
Here's the HTML:
-----------------------------
<html> <head>
<title>First Page</title>
</head>
<body>
<h1>page1</h1>
<form name=myform method="post" action="page2.html">
<input type=text name="city" maxlength="30">City
<br><br>
<select name="state" size="1">
<option value="">
<option value="AL">AL
<option value="AK">AK
</select>
<br><br>
<input type=submit value="Submit">
</form>
<a href="page2.html">Page 2</a>
<br><br>
<hr>
</body> </html>
Here's the code:
------------------------
void testWritePageContentsToFile()
throws java.io.IOException
{
String myUrl = "http://localhost:/page1.html";
WebClient webClient = new WebClient();
HtmlPage page = (HtmlPage) webClient.getPage(new URL(myUrl));
FileOutputStream fout;
try
{
// Open an output stream
fout = new FileOutputStream ("c:/sandbox/out.html");
// Print a line of text
PrintStream psout = new PrintStream(fout);
psout.println (page.getWebResponse().getContentAsString());
// Close our output stream
fout.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to write to file");
System.exit(-1);
}
}
Mark Dematteis
|