Windows curl 批处理文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35491184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:28:19  来源:igfitidea点击:

Windows curl Batch file

windowsshellbatch-filecurlmailgun

提问by Ganesh Rathinavel

I want to make a mailgun curl call using windows batch file. Since windows shell doesn't support multiple lines, how can I execute the below curl function in windows batch file?

我想使用 Windows 批处理文件进行 mailgun curl 调用。由于 windows shell 不支持多行,如何在 windows 批处理文件中执行以下 curl 函数?

curl -s --user 'api:key-xxxxxxxxxx' \
    https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages \
    -F from='user <[email protected]>' \
    -F to='user <[email protected]>' \
    -F subject='Hello' \
    -F text='body!' \
    -F [email protected] \

Update

更新

When I tried to execute the command after removing the multiple lines it returned this error:

当我在删除多行后尝试执行命令时,它返回了这个错误:

    curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from='user  -F to='user  -F subject='Hello' -F text='body!' -F [email protected] 0<[email protected] 1>'
The system cannot find the file specified.

PS: The attachment file is in the same directory

PS:附件文件在同一目录下

Thanks!

谢谢!

回答by SachaDee

simply on one line and put the <>redirection char between "or escape it with ^:

只需在一行上并将<>重定向字符放在中间"或使用^以下命令对其进行转义:

curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from="user <[email protected]>" -F to="user <[email protected]>" -F subject='Hello' -F text='body!' -F [email protected]

You can also create variable for each element :

您还可以为每个元素创建变量:

set "$ApiKey=api:key-xxxxxxxxxx"
set "$Url=https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages"
set "[email protected]"
....

and then 

curl -s --user '%$ApiKey%' %$Url% -F from="user <%$From%>" -F to= ....