Powershell 如何卷曲Watson';来自Windows的个人见解?

Powershell 如何卷曲Watson';来自Windows的个人见解?,powershell,curl,Powershell,Curl,Personal Insights教程要求使用以下cURL命令: curl -X POST --user {username}:{password} \ --header "Content-Type: application/json" \ --data-binary "@{path_to_file}profile.json" \ "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=201

Personal Insights教程要求使用以下cURL命令:

curl -X POST --user {username}:{password} \
--header "Content-Type: application/json" \
--data-binary "@{path_to_file}profile.json" \
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"
我将其翻译为:

curl -X POST --user myun:mypw \
--header "Content-Type: application/json" \
--data-binary "@C:\mypath\profile.json" \
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"
我下载并安装了cURL,但在PowerShell中不断出现这些可怕的错误:

At line:2 char:3
+ --header "Content-Type: application/json" \
+   ~
Missing expression after unary operator '--'.
At line:2 char:3
+ --header "Content-Type: application/json" \
+   ~~~~~~
Unexpected token 'header' in expression or statement.
At line:3 char:3
+ --header "Accept: text/csv" \
+   ~
Missing expression after unary operator '--'.
At line:3 char:3
+ --header "Accept: text/csv" \
+   ~~~~~~
Unexpected token 'header' in expression or statement.
At line:4 char:3
+ --data-binary "C:\mypath\profile.json" \
+   ~
Missing expression after unary operator '--'.
At line:4 char:3
+ --data-binary "C:\mypath\profile.json" \
+   ~~~~~~~~~~~
Unexpected token 'data-binary' in expression or statement.
At line:5 char:3
+ --output "C:\profile.csv" \
+   ~
Missing expression after unary operator '--'.
At line:5 char:3
+ --output "C:\profile.csv" \
+   ~~~~~~
Unexpected token 'output' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
以下是我尝试过的:

  • myun:mypw
    置于双引号中
  • 在数据二进制文件之后删除符号
  • 谷歌搜索“表达式或语句中意外的标记‘header’”,但这似乎是一个个案基础(这意味着这可能也是一个)
  • 我知道windows的cURL不喜欢单引号,但我在这里没有看到任何单引号,我不确定是否有任何其他特性可能会影响这一点

    • PowerShell中的换行符不是通过
      \
      转义的,而是通过后面的勾号`。因此,如果要在PowerShell中执行此命令,请避免转义换行符,或者改用反勾号:

      curl -X POST --user myun:mypw `
      --header "Content-Type: application/json" `
      --data-binary "@C:\mypath\profile.json" `
      "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"
      

      不过,避免背虱会更好,因为它们很难阅读。

      好的,非常感谢。背面的记号起作用了,但现在它显示
      调用WebRequest:找不到与参数名称“X”匹配的参数。
      (我也尝试了
      XPOST
      )现在您遇到了另一个问题:在PowerShell中
      curl
      调用WebRequest的别名,这是一个cmdlet,其语法与您正在使用的命令不同。您最好在这里使用cmd而不是PowerShell。好的,我还在cmd中转义换行符吗?是的,但这次转义字符是插入符号^。