You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用curl将命令或脚本执行结果以POST请求发送?

单行curl命令发送命令执行结果作为POST数据

Linux 终端

直接利用Shell命令替换功能,将ifconfig的输出作为POST请求内容:

curl -X POST -d "$(ifconfig)" https://your-server-endpoint.com
  • -X POST:明确指定HTTP请求方法为POST
  • -d "$(ifconfig)":通过$(...)语法将ifconfig的执行结果作为POST数据传递,该语法会把括号内命令的输出直接替换到当前位置
  • 若需指定请求的Content-Type(比如纯文本格式),可添加-H "Content-Type: text/plain"参数:
curl -X POST -H "Content-Type: text/plain" -d "$(ifconfig)" https://your-server-endpoint.com

Windows CMD

Windows CMD无类似Linux的命令替换语法,可通过管道将ipconfig(Windows对应Linux的ifconfig)的输出传递给curl:

ipconfig | curl -X POST --data-binary "@-" https://your-server-endpoint.com
  • ipconfig |:将ipconfig的输出通过管道传给后续curl命令
  • --data-binary "@-":告知curl从标准输入读取数据作为POST内容,@-代表读取标准输入,--data-binary会保留输出中的换行和原始格式
  • 同样可添加Content-Type参数:
ipconfig | curl -X POST -H "Content-Type: text/plain" --data-binary "@-" https://your-server-endpoint.com

补充说明

  • 请将https://your-server-endpoint.com替换为实际的服务器接口地址
  • 若使用Windows PowerShell,命令可简化为:
curl -Method Post -Body (ipconfig) -Uri https://your-server-endpoint.com

内容的提问来源于stack exchange,提问作者Vraj Bharambe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 07:39:24