【问题标题】:curl pass authentication using variablecurl 使用变量通过身份验证
【发布时间】:2017-10-06 14:29:17
【问题描述】:

关于如何使用 curl 中的变量通过身份验证有什么建议吗?

这就是我所拥有的,尝试不带引号播放,但没有运气。

 curl -X GET "https://example.com/site" \
 -H 'x-auth-email: "${API_EMAIL}"' \
 -H 'x-auth-key: "${API_KEY}"' \
 -H "Content-Type: application/json"

【问题讨论】:

    标签: bash variables curl


    【解决方案1】:

    Shell 变量只在双引号内展开,不在单引号内:

    curl "https://example.com/site" \
     -H "x-auth-email: \"${API_EMAIL}\"" \
     -H "x-auth-key: \"${API_KEY}\"" \
     -H "Content-Type: application/json"
    

    【讨论】:

    • 哈,我错过了。这几乎肯定是问题所在。
    【解决方案2】:

    你试过了吗:

    --user "${USERNAME}:${PASSWORD}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-29
      • 2011-08-31
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      相关资源
      最近更新 更多