免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5423 | 回复: 6
打印 上一主题 下一主题

[系统安装] 如何将输出通过管道传给curl [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-28 15:22 |只看该作者 |倒序浏览
下面是一行虚拟的命令
  1. ping 127.0.0.1 | curl -d -X POST http://localhost
复制代码
希望能够将一个程序的输出通过管道作为curl的-d 参数
不知道是不是有办法

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
2 [报告]
发表于 2012-06-28 15:45 |只看该作者
本帖最后由 ulovko 于 2012-06-28 15:49 编辑
  1. ping 127.0.0.1 | curl -d /dev/fd/0 -X POST http://localhost
复制代码
       -d, --data <data>
              (HTTP)  Sends  the  specified data in a POST request to the HTTP
              server, in the same way that a browser  does  when  a  user  has
              filled  in an HTML form and presses the submit button. This will
              cause curl to pass the data to the server using the content-type
              application/x-www-form-urlencoded.  Compare to -F, --form.

              -d,  --data  is  the  same  as --data-ascii. To post data purely
              binary, you should instead use the --data-binary option. To URL-
              encode the value of a form field you may use --data-urlencode.

              If  any of these options is used more than once on the same com-
              mand line, the data pieces specified  will  be  merged  together
              with  a  separating  &-symbol.  Thus,  using  '-d name=daniel -d
              skill=lousy'  would  generate  a  post  chunk  that  looks  like
              'name=daniel&skill=lousy'.

              If  you  start  the data with the letter @, the rest should be a
              file name to read the data from, or - if you want curl  to  read
              the  data  from stdin.  The contents of the file must already be
              URL-encoded. Multiple files can also be specified. Posting  data
              from  a file named 'foobar' would thus be done with --data @foo-
              bar.

             If  you  start  the data with the letter @, the rest should be a
              file name to read the data from, or - if you want curl  to  read
              the  data  from stdin
.  The contents of the file must already be
              URL-encoded. Multiple files can also be specified. Posting  data
              from  a file named 'foobar' would thus be done with --data @foo-
              bar.

论坛徽章:
0
3 [报告]
发表于 2012-06-28 16:12 |只看该作者
ulovko 发表于 2012-06-28 15:45
If  you  start  the data with the letter @, the rest should be a
              file ...


thx

翻译一下
  1. -d @filename  从文件读入内容
  2. -d @- 从stdin读入内容
复制代码
所以

就应该是
  1. echo "abc" | curl -d @- http://localhost
复制代码

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
4 [报告]
发表于 2012-06-28 16:14 |只看该作者
@jueljustman 是首先要查找的地方 ^_^

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 2012-06-29 10:33 |只看该作者
回复 4# ulovko


    你这句话太经典了。俺们遇到命令上的问题,一般都首先是 man 一下。

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
6 [报告]
发表于 2012-06-29 10:38 |只看该作者
@snow888承蒙夸奖 倍感荣幸  ^_^

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
7 [报告]
发表于 2012-06-29 10:40 |只看该作者
@ulovko

晕,只是共同的习惯撒。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP