Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
格式化curl命令_Curl_Post_Https_Git Bash - Fatal编程技术网

格式化curl命令

格式化curl命令,curl,post,https,git-bash,Curl,Post,Https,Git Bash,在Windows Git Bash中,此curl命令起作用: curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' \ -X 'POST' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'client_id=6BfkncD9ypGMiHkjrfka5ydqrG4GLx1z&client_secret=EC5

在Windows Git Bash中,此curl命令起作用:

curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' \
  -X 'POST' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'client_id=6BfkncD9ypGMiHkjrfka5ydqrG4GLx1z&client_secret=EC5i7QG61Qg8jDmZ&grant_type=client_credentials&scope=data:read'
但当我尝试将内容格式化为-d时,它不起作用:

curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' \
  -X 'POST' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'client_id=6BfkncD9ypGMiHkjrfka5ydqrG4GLx1z&
    client_secret=EC5i7QG61Qg8jDmZ&
    grant_type=client_credentials&
    scope=data:read
  '
无论如何,我都可以格式化它,并且它可以工作?

curl选项发送一个数据,在URL并行程序的情况下,该数据应该在一行中(与JSON相反,在JSON中,数据可以在多行中)

这意味着您需要首先在变量中构建字符串,然后在curl中使用该变量

vonc@vclpMINGW64/c/测试
$data=$(打印文件“%s”
客户端id=6BfkncD9ypGMiHkjrfka5ydqrG4GLx1z&
客户机_secret=EC5i7QG61Qg8jDmZ&
授予\类型=客户端\凭据&
范围=数据:读取
“|sed”:a;N;$!ba;s/\N\s*//g')
旋度-v'https://developer.api.autodesk.com/authentication/v1/authenticate' \
-X‘邮政’\
-H'内容类型:应用程序/x-www-form-urlencoded'\
-d“${data}”
在这种情况下,有两个步骤