我使用HttpUnit时,字符发生错误 [英]  characters has occurred an error when i use the HttpUnit
问题描述
我正在使用HttpUnit模拟设计到指定url中的表单的提交按钮单击. (我正在使用 http://stu21.kntu.ac.ir/Login.aspx ).我使用以下代码获取响应页面.
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
要获取Java脚本文件时出现问题,错误是
It has the problem when wants to get the java script file, and error is
线程"main" com.meterware.httpunit.ScriptException中的异常: 脚本'var shuffleArray = new Array();
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.
推荐答案
JS文件(public.js)具有字节顺序标记".默认情况下,HTTPUnit
将访问 ISO-8859-1 .通过在HTTPUnitOptions
中调用setDefaultCharacterSet
并将字符集更新为UTF-8
,只要没有在请求开头指定一个字符集,HTTPUnit
会将请求解释为UTF-8
.可以在此处找到使用HTTPUnit的更多示例.
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.
这篇关于我使用HttpUnit时,字符发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!