在applescript中,使用curl时如何发送http头?

在applescript中,使用curl时如何发送http头?,curl,applescript,Curl,Applescript,我有一个功能强大的shell脚本,看起来像这样(在终端中工作): 但是,当我尝试在Applescript中使用do shell script时,会出现以下错误: curl: no URL specified! curl: try 'curl --help' or 'curl --manual' for more information sh: line 1: -H: command not found sh: line 2: -H: command not found sh: line 3: h

我有一个功能强大的shell脚本,看起来像这样(在终端中工作):

但是,当我尝试在Applescript中使用
do shell script
时,会出现以下错误:

curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
sh: line 1: -H: command not found
sh: line 2: -H: command not found
sh: line 3: https://example.com/api/v1/user/...: No such file or directory
以下是应用脚本:

do shell script "curl -X POST --compressed -H 'Content-Type:application/json'
  -H 'x-api-user: hdfjdfpjefpoj'
  -H 'x-api-key: fpjefpojwpfjmwefpj'
  https://example.com/api/v1/user/..."
我发现一些线索表明,出于安全原因,
DoShell脚本
的行为与终端不完全相同。但我还没有找到解决这个问题的线索


没有标题信息的同一Applescript成功地传递了URL,但我需要在标题中发送我的凭据。

我认为这是因为您的命令位于多行。而不是一个

线索是
sh:line 1:-H:command not found

这表示shell正在尝试查找名为-H的命令,但未找到该命令

在大多数情况下,命令总是命令行字符串中的第一个单词

这意味着-H选项被解释为命令,因为它们是一行中的第一个单词。 -H显然是卷曲的一个选项,并且应该在同一行中跟随它

在一条线上试试看

do shell script "curl  -X POST --compressed -H 'Content-Type:application/json'  -H 'x-api-user: hdfjdfpjefpoj'  -H 'x-api-key: fpjefpojwpfjmwefpj'  https://example.com/api/v1/user/..."

击掌!谢谢你的帮助。
do shell script "curl  -X POST --compressed -H 'Content-Type:application/json'  -H 'x-api-user: hdfjdfpjefpoj'  -H 'x-api-key: fpjefpojwpfjmwefpj'  https://example.com/api/v1/user/..."