`
moshangchenzi
  • 浏览: 51630 次
  • 性别: Icon_minigender_1
  • 来自: 南宁
社区版块
存档分类
最新评论

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

阅读更多
  1. /**
  2.  * 用HttpUnit保持状态
  3.  * HttpUnit所需类库  httpunit.jar;js.jar;nekohtml.jar;Tidy.jar;xmlParserAPIs.jar
  4.  * */
  5. import com.meterware.httpunit.WebConversation;
  6. import com.meterware.httpunit.WebResponse;
  7. public class TestHTTPUnit {
  8.     private static WebConversation wc = null;//WebConversation对象
  9.     public static void main(String[] args) throws Exception {
  10.         setUp();
  11.         assertPage(getWebPage("http://localhost/setCookies.html"));//设置Cookie
  12.         assertPage(getWebPage("http://localhost/getCookies.jsp"));//读取Cookie
  13.     }
  14.     private static void setUp() {
  15.         wc = new WebConversation();
  16.     }
  17.     private static WebResponse getWebPage(String url) throws Exception {//
  18.         return wc.getResponse(url);//getResponse()方法获取WebResponse对象,代表来自HTTP服务器的反馈信息
  19.     }
  20.     private static void assertPage(WebResponse wp) throws Exception {
  21.         System.out.println(wp.getTitle());//getTitle()获取网页标题
  22.         System.out.println(wp.getText());//getText()  获取网页原文
  23.     }
  24. }
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics