Linux服务器本地POST接口测试
有时候在服务器启动后端服务后,端口没有放开,用Postman或Apifox没法测试,那么就只能在服务器上进行测试,有两种方法:
1.直接在命令上带上请求体:
curl --location --request POST 'http://127.0.0.1:8081/api/v1/test' \
--header 'Content-Type: application/json' \
--data '{"attribute1": "","attribute2": "","attribute3": "","attribute4": "","attribute5": ""
}'
这种的话如果请求体某个属性的内容过大过长的话就不方便,比如Base64编码,用这种方式复制到服务器上都要加载很久,所以可以用第二种方法。
2.把请求体放在文件中:(推荐)
curl -X POST -H "Content-Type: application/json" -d @/home/test/test.json http://127.0.0.1:8081/api/v1/test