您的位置:首页 > 理论基础 > 计算机网络

JDK6.0学习笔记(十七)用HttpUnit保持状态

2008-11-19 00:36 288 查看
/**
* 用HttpUnit保持状态
* HttpUnit所需类库 httpunit.jar;js.jar;nekohtml.jar;Tidy.jar;xmlParserAPIs.jar
* */

import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;

public class TestHTTPUnit {
private static WebConversation wc = null;//WebConversation对象

public static void main(String[] args) throws Exception {
setUp();
assertPage(getWebPage("http://localhost/setCookies.html"));//设置Cookie
assertPage(getWebPage("http://localhost/getCookies.jsp"));//读取Cookie
}

private static void setUp() {
wc = new WebConversation();
}

private static WebResponse getWebPage(String url) throws Exception {//
return wc.getResponse(url);//getResponse()方法获取WebResponse对象,代表来自HTTP服务器的反馈信息
}

private static void assertPage(WebResponse wp) throws Exception {
System.out.println(wp.getTitle());//getTitle()获取网页标题
System.out.println(wp.getText());//getText() 获取网页原文
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: