在 Linux 操作系统上对后端程序进行测试的时候,需要进行模拟连接或者书写测试脚本
使用curl命令来执行HTTP GET/POST 请求
使用方法
get请求
命令格式: curl protocol://address:port/url
访问百度curl http://www.baidu.com
post请求
a. 参数直接在header里面的命令格式:curl -d "args" "protocol://address:port/url" 获取天气数据,通过POST方法请求 > curl -d "city=dongguan&appkey=8010132dcf54491a4eaa387f4db61774" "https://way.jd.com/he/freeweather"
b. json参数数据直接在body里面的
命令格式:curl -H "Content-Type:application/json" -X POST --data (json.data) URL
> curl -H "Content-Type:application/json" -X POST --data '{"message": "sunshine"}' http://localhost:8000/