想測試接口功能虑绵,get 請求還能在瀏覽器地址欄敲敲尿瞭,測測,post怎么模擬翅睛?
找到兩個不錯的方法声搁,一是postman; 二是使用curl
postman
chrome 添加postman interceptor, postman插件:
postman插件.png
打開postman, 選擇create new => create a basic request
image.png
可以創(chuàng)建collection,類似于用文件夾來管理你的各種請求, 隨后輸入請求方式宏所,參數(shù)酥艳,點擊send就可以模擬發(fā)送請求了,下方就是response爬骤。postman, 你值得擁有
image.png
curl
百科一下:
curl是利用URL語法在命令行方式下工作的開源文件傳輸工具充石。它被廣泛應用在Unix、多種Linux發(fā)行版中霞玄,并且有DOS和Win32骤铃、Win64下的移植版本。
常用的參數(shù):
-d/ --data curl 默認是get, -d/ —data可以指定post 傳遞的數(shù)據(jù)
-H/--header 自定義頭信息傳遞給服務器
-o -- output 將輸出寫到該文件中
-O -- remote-name 將輸出寫到該文件中 保留遠程文件名
-T 上傳文件
舉個栗子:
curl http://localhost:8080/test
curl -d "x=1" http://localhost:8080/test
curl -H '' "x=1" http://localhost:8080/test