Linux-curl指令

一、GET请求

1.1 不带参数

curl http://IP地址/实际的接口地址

curl http://localhost/test/getData

1.2 带参数

  1.2.1 参数不带中文

curl http://IP地址/test/getData?name=tqf\&tel=123456789

 1.2.2 参数值带中文的要URcode编码

curl http://IP地址/test/getData?name=%E5%88%98%E5%98%89%E8%AF%9A\&tel=123456789

注意的地方:多个参数需要添加反斜杠 \ ,&在shell脚本中有特殊的意义(以daemon运行)所以只要在&前加上 反斜杠 \ 转义一下就好了

二、POST请求

2.1 不带参数

curl -k -H "Content-Type: application/json" -X POST  https://IP地址/webapi/refreshtoken

参数解析

1、-k 是代表不校验https证书的安全性

2、-H 设置请求参数的格式 application/json、application/x-www-form-urlencoded

3、-X POST 就是post类型请求

2.2 带参数 x-www-form-urlencoded形式

curl -k -H "Content-Type:application/x-www-form-urlencoded" -XPOST https://IP地址/webapi/refreshtoken -d 'appKey=233db171-d934-4317-a3a0-6f26e7669842&requestTime=1629355977367&sign=f2690f05b2f4507b56aad7ae4c8b1572'

2.3 带参数 json格式

curl -H "Content-Type:application/json" -H "Data_Type:msg" -X POST --data '
    [{
		"name": "张三",
		"age": 25,
		"sex": "男"
	},
	{
		"name": "wangmei",
		"age": 25,
		"sex": "女"
	}]' http://IP地址/test/saveData

2.4 header参数

curl -k -H "Content-Type:application/x-www-form-urlencoded" -H "name:tqf" -X POST https://IP地址/test -d 'appKey=233db171-d934-4317-a3a0-6f26e7669842&requestTime=1629355977367&sign=f2690f05b2f4507b56aad7ae4c8b1572'

参数 内容
-H 请求头
-d 内容
-X 请求协议

猜你喜欢

转载自blog.csdn.net/tanqingfu1/article/details/119883876
今日推荐