CURL body 自動帶入時間戳記

今天遇到同事問我一個問題,如何在 curl 自動帶入 timestamp,在這邊做一下紀錄,也讓不知道的人學習一下,使用的方法如下:

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 顯示出來:

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