我如何將此 cURL cmd 轉換為批處理腳本-
curl --request POST \
--url https://api.example.com \
--header "Authorization: Bearer token" \
--header 'Content-Type: application/json' \
--data '{"personalizations": [{"to": [{"email": "[email protected]"}]}],"from": {"email": "[email protected]"},"subject": "Subject","content": [{"type": "text/plain", "value": "Body"}]}'
這是我得到的錯誤 -
[Running] cmd /c "c:\Users\sendMail.bat"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: \
'--url' is not recognized as an internal or external command,
operable program or batch file.
'--header' is not recognized as an internal or external command,
operable program or batch file.
'--header' is not recognized as an internal or external command,
operable program or batch file.
'--data' is not recognized as an internal or external command,
operable program or batch file.
[Done] exited with code=1 in 0.078 seconds
uj5u.com熱心網友回復:
^
用 a而不是 a轉義一個新行,\
for --data
turn '
into"
和"
into \"
:
curl --request POST ^
--url https://api.example.com ^
--header "Authorization: Bearer token" ^
--header "Content-Type: application/json" ^
--data "{\"personalizations\": [{\"to\": [{\"email\": \"[email protected]\"}]}],\"from\": {\"email\": \"[email protected]\"},\"subject\": \"Subject\",\"content\": [{\"type\": \"text/plain\", \"value\": \"Body\"}]}"
uj5u.com熱心網友回復:
你添加cmd。
你只需要打開一個 CMD 視窗來執行你的 curl。
并且需要都在一條線上。
你得到的那些錯誤是因為它試圖將每一行作為命令執行。
cmd /k 'curl -X POST --url https://api.example.com -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d {"personalizations": [{"to": [{"email": "[email protected]"}]}],"from": {"email": "[email protected]"},"subject": "Subject","content": [{"type": "text/plain", "value": "Body"}]}';
PAUSE
完成測驗后,洗掉 PAUSE。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/507053.html