我的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,
}'
但是当我在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
请告诉我换行符是否有问题,如果可以,该如何避免?
您不是在寻找换行符。您真正想要的是行继续。PowerShell中的“行连续性”是反引号字符(`)。它必须是一行中的最后一个字符,并紧跟一个空格字符。
同样,Windows命令提示符也定义了行继续符。在这种情况下,它是^字符。它也必须是最后一个字符,还需要立即跟随空格字符。
要解决您的直接问题,请用反引号或^字符替换所有结尾的反斜杠。您还需要向当前没有任何行的行添加行继续标记。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句