【问题标题】:Unable to use variable in curl command [duplicate]无法在 curl 命令中使用变量 [重复]
【发布时间】:2019-08-27 03:17:44
【问题描述】:

我试图在我的 ksh 程序的 curl 命令中使用两个变量,但它不起作用。

例子:

  1. 原始网址

    curl -s --header "Content-Type:application/json" --header "Accept:application/json" -X POST --data-binary '{"username":"foo","password":"foo_pwd"}' URL site
    
  2. 在我的节目中

    user=foo
    pwd=foo_pwd
    curl -s --header "Content-Type:application/json" --header "Accept:application/json" -X POST --data-binary '{"username":"'"$user"'","password":"'"$pwd"'"}' URL site
    

我也试过用反斜杠转义双引号,但它也不起作用。

【问题讨论】:

    标签: bash shell curl ksh


    【解决方案1】:

    首先检查你的脚本

    user=foo
    pwd=foo_pwd
    echo '{"username":"'"$user"'","password":"'"$pwd"'"}'
    

    然后运行

    user=foo
    pwd=foo_pwd
    curl -s --header "Content-Type:application/json" --header "Accept:application/json" -X POST https://example.com --data-binary '{"username":"'"$user"'","password":"'"$pwd"'"}'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 2020-01-27
      • 2023-03-30
      • 2015-11-04
      • 1970-01-01
      相关资源
      最近更新 更多