gpt4 book ai didi

java - 当我使用 HttpUnit 时,“ï”字符发生错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:12:43 26 4
gpt4 key购买 nike

我正在使用HttpUnit来模拟设计到指定url的表单的提交按钮单击。 (我正在使用 http://stu21.kntu.ac.ir/Login.aspx )。我使用如下代码来获取响应页面。

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脚本文件时出现问题,错误为

Exception in thread "main" com.meterware.httpunit.ScriptException: Script 'var shuffleArray = new Array();

那么,我该如何摆脱这个问题呢?它阻止我的程序加载结果页面。

最佳答案

JS 文件 (public.js) 有一个“字节顺序标记”。默认情况下 HTTPUnit 将访问 ISO-8859-1 中的页面。通过在 HTTPUnitOptions 中调用 setDefaultCharacterSet 并将字符集更新为 UTF-8HTTPUnit 会将请求解释为 UTF-8(前提是请求中未指定字符集)。更多使用 HTTPUnit 的示例可以参见 here

关于java - 当我使用 HttpUnit 时,“ï”字符发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10914232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com