Postman很多公司測試代碼的一個常用工具栈源,掌握其用法挡爵,對我們接口的測試有很大的幫助。
一甚垦、將postman的請求轉(zhuǎn)成cURL
1. 構(gòu)造postman請求茶鹃,點擊 Code
2.??copy cURL 的請求鏈接
默認是使用長格式選項
設(shè)置使用短格式選項
3. 在命令行執(zhí)行
使用長格式選項
使用短格式選項
# curl -X POST \
? ?https://run.mocky.io/v3/e95f6c35-b3c8-43d9-b9ab-f5ce8c1054cf \
? ?-H 'cache-control: no-cache'
二、利用Chrome將請求復(fù)制為 curl 格式
有時候我們想在 postman 重現(xiàn)瀏覽器上的某個請求(比如服務(wù)器上報錯了艰亮,需要對該次請求調(diào)試)闭翩,以往可能大家會把 url、參數(shù)迄埃、header 一個個地復(fù)制到 postman 里面疗韵,然后點 postman 的 send 發(fā)送請求。
Chrome 有個很好用的功能是侄非,把請求復(fù)制為 curl 格式蕉汪。
1.右鍵請求 -> copy -> copy as curl
2.現(xiàn)在我們的粘貼板里面有個 curl 格式的請求,接下來我們打開 postman彩库,點擊左上角 Import肤无,然后點 Paste Raw Text,然后點擊 Import 完成導(dǎo)入
3.將請求的完整信息復(fù)制到了 postman骇钦,發(fā)送請求測試
三宛渐、參考
Postman上重現(xiàn)Chrome上請求的小技巧
https://learnku.com/articles/33410
將POSTMAN請求轉(zhuǎn)換為Curl
https://qastack.cn/programming/49432735/converting-a-postman-request-to-curl
Postman 導(dǎo)出 curl命令 到命令行運行 Mac OS
https://blog.csdn.net/zgpeace/article/details/109552780
Postman簡單用法以及轉(zhuǎn)cURL等命令的正確姿勢
https://blog.csdn.net/w605283073/article/details/94902637
Postman生成curl命令和request
https://blog.51cto.com/thinklili/2344301
postmanlabs/postman-code-generators
https://github.com/postmanlabs/postman-code-generators