【问题标题】: characters has occurred an error when i use the HttpUnit 字符在我使用 HttpUnit 时发生错误
【发布时间】:2012-06-10 11:16:31
【问题描述】:

我正在使用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脚本文件时出现问题,报错

线程“主”com.meterware.httpunit.ScriptException 中的异常: 脚本 'var shuffleArray = new Array();

那么,我怎样才能摆脱这个问题呢?它会阻止我的程序加载结果页面。

【问题讨论】:

  • 您的 public.js 文件中似乎有一些无效字符。它可能是“字节顺序标记”。也许您需要设置编码类型?
  • 如何设置编码类型? :-/
  • 我不是 HTTPUnit 专家,但看看 docs,您应该能够将 HTTPUnitOptions 上的 setDefaultCharacterSet 指定为 UTF-8
  • 太好了 :) 非常感谢,效果很好 :) 请将您的评论作为答案发表:)

标签: java http-unit


【解决方案1】:

如您所见,here 是 ISO-8859-1 表示形式的 UTF-8 字节顺序标记。您应该使用文本编辑器将其删除(例如 Notepad++)。

【讨论】:

  • 我无法访问 java 脚本文件。 HttpUnit下载使用.js文件!
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 2011-01-08
    • 2015-07-22
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多