【发布时间】:2018-06-26 06:57:41
【问题描述】:
我尝试运行一个 shell 脚本,其中包含一个 curl 命令,其所需的标头如下。
counter=1
H1='Content-Type: application/json'
H2='Accept: application/json'
H3='Authorization: Bearer a0a9bb26-bb7d-3645-9679-2cd72e2b4c57'
URL='http://localhost:8280/mbrnd_new/v1/post'
while [ $counter -le 10 ]
do
TEST="curl -X POST --header $H1 --header $H2 --header $H3 -d @s_100mb.xml $URL"
echo $TEST
RESPONSE=`$TEST`
echo $RESPONSE
sleep 5
done
echo "All done"
它给出一个错误
curl: (6) Could not resolve host: application
curl: (6) Could not resolve host: Bearer
curl: (6) Could not resolve host: a0a9bb26-bb7d-3645-9679-2cd72e2b4c57
<ams:fault xmlns:ams="http://wso2.org/apimanager/security"><ams:code>900902</ams:code><ams:message>Missing Credentials</ams:message><ams:description>Required OAuth credentials not provided. Make sure your API invocation call has a header: "Authorization: Bearer ACCESS_TOKEN"</ams:description></ams:fault>
给定的访问令牌和其他标头参数是正确的。直接调用'curl'时效果很好。
我尝试了不同的方法,例如使用 \" 但没有任何效果。如果有人可以提供正确的答案,我将不胜感激。
谢谢。
【问题讨论】:
-
您的示例将中断,因为替换单个标头变量 (
$H1, ...) 会扩展为包含空格的字符串。
标签: shell curl http-headers access-token