<分区>
我正在尝试执行一个使用预定义变量作为 header 的 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
我试图将 header 作为变量传递的原因是因为我正在编写一个循环遍历数组的脚本,但由于某些原因目前这不适用于 header 。为 body 传递参数没有问题。