我正在嘗試執行一個使用預定義變量作爲標題的curl命令。如何在curl命令中將標題作爲參數傳遞?
header='-H "Content-Type: application/json" -H "userGUID: 7feb6e62-35da-4def-88e9-376e788ffd97" -H "Content-Length: 51"'
而且這本質上是curl命令
curl $header -w "http code: %{http_code}\\n" -X POST -d $BODY $URL
,然後返回錯誤信息
rl: (6) Could not resolve host: application
curl: (6) Could not resolve host: 7feb6e62-35da-4def-88e9-376e788ffd97"
curl: (6) Could not resolve host: 51"
可正常工作
curl -H "Content-Type: application/json" -H "userGUID: 7feb6e62-35da-4def-88e9-376e788ffd97" -H "Content-Length: 51" -w "http code: %{http_code}\\n" -X POST -d $BODY $URL
的原因,我試圖通過標題作爲一個變量是因爲我正在編寫一個循環和數組的腳本,但目前由於某種原因,這不適用於標題。沒有任何問題爲身體傳遞參數。
分詞使得你的頭部參數爲'-H',''Content-Type:','application/json「等。我建議你使用一個數組來保存頭文件。否則,你可能需要'eval'。 – 4ae1e1
你會在curl命令中執行eval命令嗎? –