原文:http://www.cnblogs.com/xxyfhjl/p/4074186.html
poster3.1的下載地址:http://files.cnblogs.com/files/lizhigang/poster-3.1.0-fx.zip
目的:驗證http請求功能正確與否,需要發送post,get請求,則可以使用Poster插件方便簡單。
自我總結,有什么改正的地方請指出,感激不盡!
1.安裝Poster插件。
點擊firefox右上方的菜單鍵-->[ 附加組件 ],在搜索框中輸入poster點擊安裝即可
提示重啟Firefox,才能用,重啟后,在上方菜單欄[ 工具 ]-->即可看到[ Poster ]選項,說明已安裝成功。
2.創建一個maven項目"getpost",將war放入tomcat
1). 在webapp目錄下創建一個html文件:test.html
2). 表單action跳轉路徑為同級目錄下的index.jsp
3).打成war包放入tomcat
test.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <form name="Login" method="post" action="index.jsp"> User ID: <input type="text" name="name"><br> Password: <input type="password" name="password"> <input type="HIDDEN" name="from" value="welcome"> <input type="submit" value="submit"> </form> </body> </html>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <% response.setContentType("text;html;charset=utf-8"); String username=request.getParameter("name"); String password=request.getParameter("password"); System.out.println("username="+username); System.out.println("password="+password); System.out.println("servlet test success...."); %> Success! </body> </html>
3.驗證
瀏覽器測試:http://localhost:8989/getpost/test.html,輸入name和password,能正常跳轉到index.jsp,顯示hello word。
Poster模擬測試:
打開firebug,看到該post請求的參數
將請求的URL,和參數填寫到Poster中
點擊Body from Parameters按鈕,將post請求參數放入body。
點擊中間的"post"按鈕即可。
如何判斷請求成功:
1)查看控制台,控制台打印的name和password的值是否正確。
2)彈出的對話框,reponse頁面的內容正確則模擬post的請求成功。
總結:Poster插件不僅僅能發post請求,其他請求也能發。發送http請求也不止Poster這一種方式。