Win10下curl-换行符?

Kos*_*osh 3 windows curl cmd

我的IDE生成的curl可以将HTTP请求导出为curl命令。它们看起来像这样:

curl --request POST \
  --url http://test.api.local/api/tickets/route \
  --header 'accept-encoding: gzip' \
  --header 'content-type: application/json' \
  --data '{
  "start_datetime": "2020-11-10T09:30Z",
  "brand_id": 33,
  "model_id": 90,
  "class": 1,
  "country_code": "US",
  "contract_id": 120071,
}'
Run Code Online (Sandbox Code Playgroud)

但是当我在Win10命令提示符或powershell中运行它们时,出现很多错误:

PS C:\Users\Kosh> curl --request POST \
>>   --url http://test.api.local/api/tickets/route \
>>   --header 'accept-encoding: gzip' \
>>   --header 'content-type: application/json' \
>>   --data '{
>>   "start_datetime": "2020-11-10T09:30Z",
>>   "brand_id": 33,
>>   "model_id": 90,
>>   "class": 1,
>>   "country_code": "US",
>>   "contract_id": 120071,
>> }'
At line:2 char:5
+   --url http://entry.dev.tskad/api/tickets/route \
+     ~
Missing expression after unary operator '--'.
At line:2 char:5
+   --url http://entry.dev.tskad/api/tickets/route \
+     ~~~
Unexpected token 'url' in expression or statement.
At line:3 char:5
+   --header 'accept-encoding: gzip' \
+     ~
Missing expression after unary operator '--'.
At line:3 char:5
+   --header 'accept-encoding: gzip' \
+     ~~~~~~
Unexpected token 'header' in expression or statement.
At line:4 char:5
+   --header 'content-type: application/json' \
+     ~
Missing expression after unary operator '--'.
At line:4 char:5
+   --header 'content-type: application/json' \
+     ~~~~~~
Unexpected token 'header' in expression or statement.
At line:5 char:5
+   --data '{
+     ~
Missing expression after unary operator '--'.
At line:5 char:5
+   --data '{
+     ~~~~
Unexpected token 'data' in expression or statement.
At line:5 char:9
+   --data '{
+         ~
The Data section is missing its statement block.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
Run Code Online (Sandbox Code Playgroud)

请告诉我是否存在换行问题,如果是,我该如何避免?

IIn*_*ble 5

您不是在寻找换行符。你真正想要的是行延续。PowerShell 中的续行符是反引号字符 (`)。它必须是一行中的最后一个字符,并跟随一个空格字符。

同样,Windows命令提示符也定义了行继续符。在本例中,它是 ^ 字符。它还需要是最后一个字符,并且还需要紧跟在空格字符之后。

要解决您眼前的问题,请将所有结尾的反斜杠替换为反引号或 ^ 字符。您还需要向当前没有任何行继续标记的行添加行继续标记。