在web和移動端開發時,常常會調用伺服器端的restful接口進行資料請求,為了調試,一般會先用工具進行測試,通過測試後才開始在開發中使用。這裡介紹一下如何在chrome浏覽器利用postman應用進行restful api接口請求測試。
工具/原料
- chrome浏覽器
- postman
1、安裝Postman
-
1
下載下傳postman,這裡提供兩種方式。
1、通過postman官方網站直接點選百度搜尋“postman”
就可以找到。
點選“get it now it's free!”進入chrome商店下載下傳
注意:chrome商店需要到“牆外”在才能下載下傳。
如何安裝Postman,并在Chrome下使用Postman進行rest請求測試 -
2
2、離線安裝:
檔案已經放在百度雲上:
連結: http://pan.baidu.com/s/1bni9Dzp 密碼: kkgb
解壓下載下傳的檔案“Postman-REST-Client_v0.8.1”,内容檔案結構如下:
如何安裝Postman,并在Chrome下使用Postman進行rest請求測試 -
3
打開Chrome,依次選擇“選項”>>"更多工具">>“擴充程式”,
也可以在位址欄裡直接輸入:“chrome://extensions/”
打開後如下圖
勾選“開發者模式”
然後點選“加載已解壓的擴充程式”,選擇剛才我們下載下傳并解壓出來的檔案夾。
如何安裝Postman,并在Chrome下使用Postman進行rest請求測試 如何安裝Postman,并在Chrome下使用Postman進行rest請求測試 -
4
安裝好後如圖:
END如何安裝Postman,并在Chrome下使用Postman進行rest請求測試
2、進行Restful請求測試
-
1
打開chrome的“應用”,或者直接在位址欄裡輸入“chrome://apps/”也可以打開應用頁面
打開postman
如何安裝Postman,并在Chrome下使用Postman進行rest請求測試 -
2
Get請求:
在位址欄裡輸入請求url:http://localhost:9998/api/user
選擇“GET”方式,
點選"Url params",添加url params key:id , value:1
點選“send”得到json資料如下:
如何安裝Postman,并在Chrome下使用Postman進行rest請求測試 -
3
如果想要Post請求:
在位址欄裡輸入請求url:http://localhost:9998/api/user/1
選擇“POST”方式,
點選"application/x-www-form-urlencoded",
添加key:name , value:baidu-lulee007
添加key:sex , value:man
如何安裝Postman,并在Chrome下使用Postman進行rest請求測試 -
4
注意:請求支不支援post請求是由服務端決定。
如果服務端需要請求類型為json,需要在“headers”添加
key:Content-Type , value:application/json
選擇“raw”,并添加:
{
"id": 1,
"data": {
"name": "baidu-lulee007",
"sex": "man"
}
}
如何安裝Postman,并在Chrome下使用Postman進行rest請求測試