characters has occurred an error when i use the HttpUnit

落花浮王杯 提交于 2019-12-11 08:27:40

问题


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.


回答1:


The JS file (public.js) has a 'Byte Order Marker'. By default HTTPUnit will access pages in ISO-8859-1. By calling setDefaultCharacterSet in the HTTPUnitOptions and updating the character set to UTF-8, HTTPUnit will interpret the request as UTF-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.




回答2:


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++).



来源:https://stackoverflow.com/questions/10914232/%c3%af-characters-has-occurred-an-error-when-i-use-the-httpunit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!