【发布时间】:2014-07-02 21:32:10
【问题描述】:
我找到了this。
我写了这个变种:
#!/bin/bash
while read line ; do
headers="$headers -H '$line'"
done < public/headers.txt
echo $headers
curl -X PUT \
$headers \
-d @'public/example.json' \
echo.httpkit.com
在headers.txt 我有:
X-PAYPAL-SECURITY-USERID:123
X-PAYPAL-SECURITY-PASSWORD:123
但是当我运行 ./public/curl.sh 时,我没有收到要发送的标头。
我用一个环境变量隔离了这个问题:
$ x='-H some:asd'
$ curl $x echo.httpkit.com
=> header was NOT present
$ curl -H 'some:asd' echo.httpkit.com
=> header was present
$ curl -H some:asd echo.httpkit.com
=> header was present
如何在标题部分正确插入变量?
【问题讨论】:
-
你怎么知道标题是否存在?我正在检查
curl -v $x echo.httpkit.com 2>&1 >/dev/null | grep some:,它匹配,看起来标题就在那里。你的“curl --version”是什么?