Linux curl 命令

查询出口IP

1
curl icanhazip.com

GET 请求

1
curl https://www.baidu.com?q=xxxx

POST 请求

1
curl http://ip:port/api/add_user -XPOST -d "send message..."

发送 POST JSON 请求

1
curl -H "Content-Type: application/json" -X POST  --data '{"data":"1"}' http://127.0.0.1/

使用代理

1
curl -x 192.168.2.5:3128 https://www.baidu.com?q=xxxx

输出请求信息

1
2
3
4
5
6
7
8
# http_code
# time_connect
# time_starttransfer
# time_total
# size_download
# speed_download
# 参考地址:
curl http://www.baidu.com?q=xxxx -so /dev/null -w "%{http_code}\t%{time_connect}\t%{time_starttransfer}\t%{time_total}\t%{size_download}\t%{speed_download}\t"

下载文件并重命名

1
2
# culr -L <url> -o <filename>
curl -L http://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/CentOS-Base.repo \

发送邮件

1
2
3
4
5
6
7
8
9
10
11
# mail.txt 内容
tee ./mail.txt <<-'EOF'
From:test01@163.com
To:test02@163.com
Subject: test send email

test send email!!!!!!
EOF

# 发送邮件
curl -s --url "smtp://smtp.163.net" --mail-from "test01@163.com" --user "test01@163.com:123456" --mail-rcpt "test02@163.com" --upload-file mail.txt

参数说明

  • –url:邮箱服务
  • –mail-from:发送者邮箱
  • –user:发送正邮箱账号密码,账号密码使用冒号隔开
  • – mail-rcpt:接收者邮箱
  • –upload-file:邮件内容,写法参考 mail.txt
  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/aea02818.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!