Linux/unix curl命令使用

4 篇文章 0 订阅

curl 命令解析

curl 是 linux/unix 命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思, 语法:语法:# curl [option] [url]
#  curl --help 
-A/--user-agent <string>         设置用户代理发送给服务器
-b/--cookie <name=string/file>   cookie字符串或文件读取位置
-c/--cookie-jar <file>           操作结束后把cookie写入到这个文件中
-C/--continue-at <offset>        断点续转
-d/--data <data>                 HTTP POST数据(H)
-D/--dump-header <file>          把header信息写入到该文件中
-e/--referer                     来源网址
-H/--header <line>               添加 HTTP 请求的标头
-o/--output <file>               把输出写到该文件中
-O/--remote-name                 把输出写到该文件中,保留远程文件的文件名
-T/--upload-file <file>          上传文件
-u/--user <user[:password]>      设置服务器的用户和密码
-v/--verbose                     输出通信的整个过程
-x/--proxy <host[:port]>         在给定的端口上使用HTTP代理
-X/--request <command>           指定要使用的请求命令

curl http://www.baidu.com

在这里插入图片描述

-A 指定请求参数user_agent

应用场景:

  1. 获取不同的设备素材;

  2. 伪造请求的设备;

curl -A "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0)" https://www.baidu.com

-b 指定请求时的cookie

应用场景:

  1. 浏览器和服务器 私有标识;
  2. 获取需要认证的网址内容
curl -b 'foo=bar' https://www.baidu.com
curl -b 'foo=bar;foo2=bar2' https://www.baidu.com
curl -b cookie.jar https://www.baidu.com

在这里插入图片描述

-D 将请求的header保存在本地

curl -D header.txt https://www.baidu.com

在这里插入图片描述

-e 设置访问当前url来源

应用场景:

  1. 模拟用户行为时使用
  2. 防盗链
curl -e "www.baidu.com" https://passport.baidu.com/v2/
curl -H 'Referer: www.baidu.com' https://www.baidu.com/

-H 设置请求header

curl -H 'Content-Type: application/json' https://www.baidu.com
curl -H 'Referer: www.ddd.com' -H 'Hostname: www.sss.com' https://www.baidu.com/
# 多个参数设置

在这里插入图片描述

-o 和 -O 保存输出结果(下载文件)

curl https://www.baidu.com >> baidu.html  # 只有这个不是下载
curl -o baidu.html https://www.baidu.com 
curl -O https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

-T 上传文件

curl -T baidu_logo.png ftp://10.88.16.58:2121/amap/baidu_logo.png
curl -T baidu_logo.png -u ftp:ftp ftp://10.88.16.58:2121/amap/baidu_logo.png

-v 调试日志

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

-x proxy服务器以及其端口

curl -x 100.94.22.41:1000 http://127.0.0.1:1000/cron/spucard/autoWithhold

在这里插入图片描述

查看网页返回值

curl -o /dev/null -s -w %{http_code} www.baidu.com
Curl –i www.baidu.com 
Curl –v www.baidu.com 

在这里插入图片描述

-X 指定请求方式

post请求时候 -d 指定data

curl -d 'appId=0031&serviceId=pre_023840280234208' -X POST https://qa7.beneucard.com/hfas/bzjr/loan/repay/plan
curl -d 'appId=0031' -d'serviceId=pre_023840280234208' -X POST https://qa7.beneucard.com/hfas/bzjr/loan/repay/plan
curl -H "Content-Type: application/json&aa:bb" -d '@data.json' -X POST https://qa7.beneucard.com/hfas/bzjr/repay/calculate

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

csdn_WDX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值