I am using the HttpUnit to simulate the submit button click of the form that designed into the specified url. (I am using http://stu21.kntu.ac.ir/Login.aspx). I use the code as follow to get response page.
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest("http://stu21.kntu.ac.ir/Login.aspx");
WebResponse response = conversation.getResource(request);
WebForm loginForm = response.getForms()[0]; //Form has been got successfully
request = loginForm.getRequest();
request.setParameter("txtusername", "8810103" );
request.setParameter("txtpassword", "8810103" );
response = conversation.getResponse( request ); //error while getting the .js
It has the problem when wants to get the java script file, and error is
Exception in thread "main" com.meterware.httpunit.ScriptException: Script 'var shuffleArray = new Array();
So, how can i get rid of this problem ? It prevents my program to load the result page.
The JS file (public.js) has a 'Byte Order Marker'. By default
HTTPUnit
will access pages in ISO-8859-1. By callingsetDefaultCharacterSet
in theHTTPUnitOptions
and updating the character set toUTF-8
,HTTPUnit
will interpret the request asUTF-8
, provided that there wasn't a Character Set specified on the request to start with. Some more examples of the use of HTTPUnit can be found here.As you can see here it's UTF-8 Byte Order Mark in ISO-8859-1 representation. You should remove it with text-editor( e.g. Notepad++).