介紹
curl 是常用的指令行工具,用來請求 Web 伺服器。它的名字就是用戶端(client)的 URL 工具的意思。
GET
curl預設協定就是GET,直接使用 curl url相當于直接用浏覽器打開。
POST
curl 使用 -X POST 可以發送POST消息。如果要post json資料,如:
curl -H "Content-Type:application/json" -X POST -d '{"uid":"123"}' http://127.0.0.1:3000/rest/test
參數解析:
- -H 請求頭。post json需要添加 -H “Content-Type: application/json”
- –X 請求協定。
- –d post的body内容,如果是json資料,外層再加一個’包含