curl命令

curl案例:


查看所有curl命令: man curl或者curl -h


-X:指定 HTTP 请求方法,如 GET、POST、PUT、DELETE 等。

curl -X POST https://www.baidu.com
curl -X GET https://www.baidu.com

-x :指定 HTTP 请求的代理

# 指定 HTTP 请求通过myproxy.com:8080的 socks 代理发出
curl -x socks://james:cats@myproxy.com:8080 https://www.baidu.com

-H:指定 HTTP 请求头,如 Content-Type、Authorization 等。

curl -H 'Content-Type:application/x-www-form-urlencoded' https://www.baidu.com

-d:指定 HTTP 请求体,用于发送 POST 或 PUT 请求。

curl -d 'grant_type=code&type=123' https://www.baidu.com
curl -d '{"login": "emma", "pass": "123"}' https://www.baidu.com

-i:显示 HTTP 响应头。
-o:将文件保存为命令行中指定的文件名的文件中
-O:使用URL中默认的文件名保存文件到本地
-s:静默模式,不显示进度条和错误信息
-S:只输出错误信息,通常与-s一起使用

curl -S -s -o /dev/null https://www.baidu.com

# 下载arthas.jar 包在本地
curl -O https://alibaba.github.io/arthas/arthas-boot.jar

-u:指定用户名和密码,用于进行 HTTP 基本认证。
-k:忽略 SSL 证书验证
-v:测试网络是否可达,用于调试

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

-e:设置 HTTP 的标头Referer,表示请求的来源
--data-urlencode:等同于-d,发送 POST 请求的数据体,区别在于会自动将发送的数据进行 URL 编码

curl --data-urlencode https://www.baidu.com

-b:向服务器发送 Cookie
-L:让 HTTP 请求跟随服务器的重定向(curl 默认不跟随重定向)
--limit-rate:限制 HTTP 请求和回应的带宽,模拟慢网速的环境

# 将带宽限制在每秒 200K 字节
curl --limit-rate 200k https://baidu.com

GET:https://www.baidu.com?username=aaa&password=123456

@RequestParam
	curl 
	-H "Content-Type:application/x-www-form-urlencoded"  #指定Content-Type
	-d 'username=aaa&password=123456' #传输的数据
	https://www.baidu.com #url

	curl 
	-H "Content-Type:application/x-www-form-urlencoded"
	'https://www.baidu.com?username=aaa&password=123456'

POST:https://www.baidu.com

@RequestBody
	curl 
	-i 
	-X POST  #请求方式
	-H "Content-type:application/json"  #指定Content-Type
	-d '{"user": "admin", "passwd":"12345678"}'  #传输的数据
	https://www.baidu.com #url

	 curl 
	 -X POST 
	 -H "Content-Type: application/json" 
	 --header "Accept: application/json;charset=UTF-8" 
	 -d "{\"dcmType\":\"p32sccs2\"}" #传输的数据
	"http://127.0.0.1:8556/test"   #url

@RequestParam
	curl -X POST 'http://localhost:8888/interface_url?param1=value1&param2=value2'
	-H "tenant-tag:tenant1"
	-H 'Content-Type: application/json'

#登陆后网页被重定向
curl -L  -d "username=admin&password=admin" "www.xxx.com/doLogin"  

#保存登陆cookie信息到文件,
#-c :保存cookie信息
#-D:保存整个header信息,包括cookie
curl -c cookie.txt  -d "username=admin&password=admin" "www.xxx.com/doLogin"  
#携带登陆信息进行post请求需要-b:指定使用哪个文件
curl -L -b cookie.txt -d "key=value" "url"  


ifconfig.me 查看本地的IP地址

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值