gpt4 book ai didi

java - HTTPUnit 代码错误

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

我正在尝试学习 HTTPUnit 并已阅读 http://httpunit.sourceforge.net/doc/cookbook.html 上提到的食谱

但是当我尝试这个非常简单的代码时

package httpUnit.test;    
import java.io.IOException;
import org.xml.sax.SAXException;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

/*** Hello world!**/

public class App{
public static void main( String[] args ) throws IOException, SAXException {
System.out.println( "Trying HTPUnit library");
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest("http://localhost:8080/proof/demo.html");
WebResponse resp = wc.getResponse(req);

/* WebLink[ ] link = resp.getLinks();
for (int i=0; i<link.length; i++) {
System.out.println(link[i].getText());
}
System.out.println(link.length);
*/
}
};

我收到以下错误:

TypeError: undefined is not a function. (httpunit; line 15)
at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597)
at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557)
Error continues.....

Exception in thread "main" com.meterware.httpunit.ScriptException: Script '/*!
* jQuery JavaScript Library v1.6
* http://jquery.com/

有人可以弄清楚可能是什么问题吗?我无法理解。我已经创建了具有 Maven 依赖项的 Maven 项目 http://mvnrepository.com/artifact/httpunit/httpunit/1.6.1

我已将 demo.html 托管在 tomcat 的proof 文件夹中,该文件夹在浏览器中可以正常打开。

最佳答案

我认为问题仅出在 javascript 上。

结账 http://httpunit.sourceforge.net/doc/faq.html#javascript

并使用 HttpUnitOptions.setScriptingEnabled(false);

我想这样就可以了。

关于java - HTTPUnit 代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12348262/

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