本文介绍了curl:参数列表太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过带有curl post的Sparkpost API发送带有附件pdf文件的电子邮件.
I want to send an email with attached pdf file through the Sparkpost API with curl post.
要插入我使用的pdf文件(我的test.pdf为〜200KB)
To insert the pdf I use (my test.pdf is ~ 200KB)
"data":"'$(cat test.pdf} | base64 --wrap=0)'"
但是以某种方式无法解决以下错误:
But somehow this doesn't work out showing the following error:
/usr/bin/curl: Die Argumentliste ist zu lang (original)
/usr/bin/curl: Argument list is too long
curl命令
curl -X POST https://api.eu.sparkpost.com/api/v1/transmissions -H 'Authorization: <APIKEY>' -H 'Content-Type: application/json' -d '{
"options":{
"open_tracking":false,
"click_tracking":false,
"inline_css":false
},
"recipients":[
{
"address":{
"email":"[email protected]",
"name":"user"
}
}
],
"content":{
"from":{
"name":"sender",
"email":"[email protected]"
},
"reply_to":"[email protected]",
"subject":"subject",
"text":"textbody",
"attachments":[
{
"name":"attachmentname.pdf",
"type":"application/pdf",
"data":"'$(cat test.pdf | base64 --wrap=0)'"
}
]
}
}'
推荐答案
之所以出现此问题,是因为您试图在命令行上传递所有base64内容. curl
可以从文件中将数据加载到POST中,我建议这样做.可以在手册页中找到更多信息,但是基本格式是这样:
This is coming up because you are trying to pass the entirety of the base64'd content on the command line. curl
has the ability to load in data to POST from a file, which I'd recommend doing. More information can be found in the man page, but the basic format is this:
curl -X POST -d @filename.txt https://website.com/path
这篇关于curl:参数列表太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!