From: Sling G. <sli...@re...> - 2009-02-12 09:30:38
|
Hi Sorry for the delay. Below is a simple class and html file that gives me the error I described. You can set the url for the post to anything it fails before the request is sent. I hope this is enough info. TestCase.class ----------------------------------------- package junittests; import java.net.URL; import org.junit.Test; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebRequestSettings; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class TestCase { @Test public void test() { try { WebRequestSettings reqSet = new WebRequestSettings(new URL( "http://localhost/test.html"), HttpMethod.POST); HtmlPage page = ReporterTestHelper.webClient.getPage(reqSet); Thread.sleep(5 * 1000); System.err.println(page.getWebResponse().getContentAsString()); } catch (Exception e) { e.printStackTrace(); } } } ----------------------------------------- test.html ----------------------------------------- <html> <head> <title>Test Case</title> <script type="text/javascript"> function createXMLHttpRequest() { if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (typeof ActiveXObject != "undefined") { return new ActiveXObject("Microsoft.XMLHTTP"); } else { throw new Error("XMLHttpRequest not supported"); } } function ajax(parArr, callback) { var http = createXMLHttpRequest(); var params = ""; for (var i=0; i<(parArr.length-1); i++) { params = params + parArr[i]+"&"; } params = params + parArr[parArr.length-1]; http.open("POST", "/test.html", true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() {//Call a function when the state changes. if(http.readyState == 4 && http.status == 200) { this.callbackFunction(http.responseText); } } this.callbackFunction = callback || function () { alert("Missing callback function!")}; http.send(params); } function getObjectByID(elmID) { if(document.getElementById) {elmID = document.getElementById(elmID);} else if(document.all) {elmID = document.all[elmID];} else if(document.layers) {elmID = this._getLayer(elmID);} else if(document.forms) { if(document.forms[elmID]) {elmID = document.forms[elmID];} else { for(var i=0; i<document.forms.length; i++) { if(document.forms[i][elmID]) { elmID = document.forms[i][elmID]; break; } } } } else {elmID = null;} return elmID; } function callback(data){ var obj = getObjectByID('testbtn'); obj.disabled=false; } ajax(['ACTION=99','TEST=22'], callback); </script> </head> <body> Test Case<br /> <button disabled="true" id="testbtn">Get It</button> </body> </html> ----------------------------------------- Thanks Sling > Dear Sling, > > I am afraid you need to provide a minimal test case that shows the error, > otherwise it will be unlikey that someone else would encounter it. > > Yours, > Ahmed > > ________________________________ > From: "sli...@re..." > <sli...@re...> > To: htm...@li... > Sent: Monday, February 9, 2009 9:51:24 AM > Subject: Re: [Htmlunit-user] (no subject) > > Hi > > Thanks for responding so quickly. I am using HtmlUnit 2.4 and > HtmlUnit-core-js-2.4. When I check the access logs the second url never > even gets queried, it seems to fail somewhere in the .send(param) call. > > The ajax function gets called via a second function similar to your test > function but instead of using an onclick it is called as from the <script> > tags in the page header. e.g. > > <head> > <script type="text/javascript"> > ....ajax and test function here > > test(); > </script> > > To shed some light on why the page does this in case it helps, the ajax > query triggers a server based data retrieval and rendering process that > can potentially take some time. To provide a friendlier user experience a > "Please wait" page is loaded with the ajax request returning when the > rendering is complete and alerting the user they can now download the > result. > > Thanks > > > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with > Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code > to > build responsive, highly engaging applications that combine the power of > local > resources and data with the reach of the web. Download the Adobe AIR SDK > and > Ajax docs to start building applications > today-http://p.sf.net/sfu/adobe-com_______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > |