Curl 命令

基本使用

curl URL

curl https://jsonplaceholder.typicode.com/posts

  • 默认是get请求

  • 默认不会进行重定向

-X 发送请求的模式

通过使用 -X 指定发送请求的模式

# 指定GET模式发送请求
curl -X -GET URL
curl -X -GET https://jsonplaceholder.typicode.com/posts
# 指定POST模式发送请求
curl -X -POST URL
curl -X -POST https://jsonplaceholder.typicode.com/posts
# 也可以连在一起写
curl -XPOST https://jsonplaceholder.typicode.com/posts

-d 发送的数据

通过使用 -d 指定发送的数据

curl -XPOST https://jsonplaceholder.typicode.com/posts -d '{"title":"teacherDD"}'

-L 跟随重定向

# curl -L URL
curl https://www.bilibili.com
curl https://www.bilibili.com -L

-v 查看详细的报错或者问题

curl -v https://www.bilibili.com

PUT 更新数据

curl -XPUT https://jsonplaceholder.typicode.com/posts/1 -d '{"title":"teacherDD-2023"}'

DELETE 删除数据

curl -XDELETE https://jsonplaceholder.typicode.com/posts/1

其他

http 首部

添加多个首部,使用多个-H

# curl URL -H 首部
curl -X -POST https://jsonplaceholder.typicode.com/posts -H "Content-Type:application/json" -d '{"title":"teacherDD-2023-1"}'

-l 获取所有相应的首部

# curl -l URL
curl -l https://jsonplaceholder.typicode.com/posts

-O 下载目标资源

# curl -O URL
curl -O https://jsonplaceholder.typicode.com/posts

-o 下载资源并重命名

# curl -o <name> URL
curl -o baidu www.baidu.com

--limit-rate 限速

# curl --limit-rate 速度 URL
curl --limit-rate 100k -o bb.iso https://releases.ubuntu.com/22.04/ubuntu-22.04-desktop-amd64.iso

-C 下载重启继续进行

假如下载被意外停止,使用-C - 进行恢复处理,继续下载

# 被意外终止
curl --limit-rate 100k -o bb.iso https://releases.ubuntu.com/22.04/ubuntu-22.04-desktop-amd64.iso^C
# 重启
curl -C - https://releases.ubuntu.com/22.04/ubuntu-22.04-desktop-amd64.iso

--proxy 代理访问目标地址

# curl --proxy 协议://username:password@proxy-address:port URL

支持FTP

支持FTP协议下载文件
curl -u user:password -O ftp://server.com
# 上传文件
curl -u user:password -T 文件 ftp://server.com/

网课连接:https://www.bilibili.com/video/BV1n94y1U7Eu?spm_id_from=333.880.my_history.page.click

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值