curl post数据超限问题优化
2017-08-15 本文已影响137人
城边编程_认真写技术
最近通过CURL执行任务时发现数据一多就会报错,错误信息如下:
/usr/bin/curl: Argument list too long
Argument list too long,参数列表过长,简单说就是post的数据长度超过了限制。
解决办法如下:
curl -X POST -H 'content-type: application/json' \
-d @- 'https://www.baidu.com' <<CURL_DATA
{
"msgtype": "text",
"text": {
"content": ""
},
}
CURL_DATA
通过引入一个here document结构来包含较大的数据。做PHP开发的同学应该很熟悉,heredoc与nowdoc其实是一个东西,都来自 Here document 有兴趣的同学可以点击链接了解下。
下面是一些CURL的常见用法
GET
curl https://api.github.com/user?access_token=XXXXXXXXXXNoneCopy
POST
-
普通POST请求
curl --data "param1=value1¶m2=value" https://api.github.com
-
特殊字符的POST请求
curl --data-urlencode "param1=中文¶m2=空 格" https://api.github.com
-
上传文件
curl --form "fileupload=@filename.txt" https://api.github.com
-
301重定向
curl -L http://www.google.comNoneCopy
-
断点下载
curl -C - -O http://www.gnu.org/software/gettext/manual/gettext.html
更多相关文章请移步我的博客-原文链接:curl post数据超限问题优化