今天遇到同事問我一個問題,如何在 curl 自動帶入 timestamp,在這邊做一下紀錄,也讓不知道的人學習一下,使用的方法如下:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| timestamp=$(date +%s) | |
| authorization=token | |
| curl -v -H "Authorization: Bearer ${authorization}" -H 'content-type: application/x-www-form-urlencoded' -d "timestamp=${timestamp}" -X POST https://clarence.tw/api |
而有時候丟出去的 curl 又想要知道送出去的 request 有沒有正確,這時候就可以用下面的方法讓他把 request 顯示出來:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -v -H "Authorization: Bearer ${authorization}" -H 'content-type: application/x-www-form-urlencoded' -d "timestamp=${timestamp}" -X POST https://clarence.tw/api --trace-ascii /dev/stdout |