WebConversation wc = new WebConversation();
//向指定的URL發出請求
WebRequest req = new GetMethodWebRequest( " http://localhost:6888/HelloWorld.jsp " );
//給請求加上參數
req.setParameter("username","姓名");
//獲取響應對象
WebResponse resp = wc.getResponse( req );
//用getText方法獲取相應的全部內容
//用System.out.println將獲取的內容打印在控制臺上
System.out.println( resp.getText() );
4.1.3 通過Post方法訪問頁面并且加入參數
System.out.println("使用Post方式向服務器發送數據,然后獲取網頁內容:");
//建立一個WebConversation實例
WebConversation wc = new WebConversation();
//向指定的URL發出請求
WebRequest req = new PostMethodWebRequest( " http://localhost:6888/HelloWorld.jsp " );
//給請求加上參數
req.setParameter("username","姓名");
//獲取響應對象
WebResponse resp = wc.getResponse( req );
//用getText方法獲取相應的全部內容
文章來源于領測軟件測試網 http://www.k11sc111.com/