Curl使用

作用

作为客户端发送请求

HTTP常见请求

curl URL【-X -GET: 默认是 get请求】

curl -X -POST URL 【设定为post请求】或-XPOST

curl -X -POST http://172.x.x.x:8000/curl_test

curl -XPOST URL -d 数据 【在 -d 之后跟着要添加的数据】

curl -XPOST http://172.x.x.x:8000/curl_test -d '{"msgId":"035e-a601","sendType":1,"toUsers":"+8618888888888","type":1}'

HTTP首部

curl -URL -H 首部 【-H, 把首部添加到请求里, 在-H后添加首部】可以添加多个 -H 首部

curl -XPOST http://172.x.x.x:8000/curl_test -H "Content-Type:application/json" -d '{"msgId":"035e-a601","sendType":1,"toUsers":"+8618888888888","type":1}'

curl -I URL 【-I, 获取到响应里的所有首部】

curl -XPOST -I http://172.x.x.x:8000/curl_test -H "Content-Type:application/json" -d '{"msgId":"035e-a601","sendType":1,"toUsers":"+8618888888888","type":1}'

文件处理

curl -O URL 【-O, 把资源文件下载到当前所处的文件夹里】

curl -XPOST -O -I http://172.x.x.x:8000/curl_test/download/hello.jpg -H "Content-Type:application/json" -d 数据

curl -o hi.jpg URL 【-o 新文件名, 重定义文件名】

curl -XPOST -o hi.jpg -I http://172.x.x.x:8000/curl_test/download/hello.jpg -H "Content-Type:application/json" -d 数据

curl --limit-rate 速度 【–limit-rate 速度, 限制下载速度】

curl -XPOST -o hi.jpg --limit-rate 100k -I http://172.x.x.x:8000/curl_test/download/hello.jpg -H "Content-Type:application/json" -d 数据

curl -C - URL 【-C -, 如果终止 恢复下载】

curl -XPOST -o hi.jpg -C -  -I http://172.x.x.x:8000/curl_test/download/hello.jpg -H "Content-Type:application/json" -d 数据

连接与测试

curl -L URL 【-L, 跟随请求重定向】

curl -XPOST -O -I http://172.x.x.x:8000/curl_test/download/hello.jpg -L -H "Content-Type:application/json" -d 数据

curl -v URL 【-v, 会把底层的连接信息都显示出来】

curl -XPOST -O -I http://172.x.x.x:8000/curl_test/download/hello.jpg -v -L -H "Content-Type:application/json" -d 数据

curl --proxy “http://用户名:密码@代理地址:端口” URL 【通过代理访问】

curl -u 用户名:密码 -O ftp://server/hello.png	【-u: 使用小写u认证用户名密码, 使用-O-o下载文件】

curl -u 用户名:密码 -T ftp://server 【-T: 上传文件 注意目录】

实际应用

使用【实体】接收参数

curl -H "Content-Type:application/json"  -X POST  -d '{"msgId":"035e-a601","sendType":1,"toUsers":"+8619180531410","type":1}'  'http://172.x.x.x:8000/curl_test' 

使用【@RequestParam】接收参数,@RequestParam(“filePath”) String filePath, @RequestParam(“type”) String type

curl -XPOST http://172.x.x.x:8000/curl_test -d"filePath=/data/channel/media/20080913/01/&type=涉政"
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值