参考链接:
https://www.ruanyifeng.com/blog/2019/09/curl-reference.html
https://man.linuxde.net/curl
参数说明:
-v 显示请求的信息
-X 选项指定其它协议(默认GET)
-H 添加 HTTP 请求的标头
-d 传递post的参数
-d ‘login=emma’ -d ‘password=123’
-d ‘login=emma&password=123’
-d ‘@data.txt’
-o 重定向输出
curl -v -o baidu.html www.baidu.com
-F 上传文件
curl -X POST -F ‘filename=@User.xlsx’ --form ‘groupId=1’ -H ‘Content-Type: multipart/form-data’ http://localhost:8080/api/user/import
具体使用:
GET:url中传递参数
如:curl http://localhost:8080/api/user/66
DELETE:url中传递参数
curl -X DELETE http://localhost:8080/api/user/66
POST
curl -X POST -d ‘@user.json’ -H ‘Content-Type: application/json’ http://localhost:8080/api/user //以文件格式上传参数
curl -X POST -d '{“groupId”:1,“userType”:1,“userDetail”:“rich people”} ’ -H ‘Content-Type: application/json’ http://localhost:8080/api/user //以json串的形式传输
curl -X POST -d '{“groupId”:1,“userType”:1,“userDetail”:“rich people”} ’ -H ‘Content-Type: application/json’ http://140.143.154.214:8080/api/user //以json串的形式传输
curl -X POST -d ‘groupId=1&userType=1&userDetail=Tsinghua&createUser=Laiyigui’ -H ‘Content-Type: application/json’ http://localhost:8080/api/user //以字符串的形式上传参数(存在问题)
curl -X POST -d ‘groupId=1’ -d ‘userType=1’ -d ‘userDetail=Tsinghua’ -d ‘createUser=Laiyigui’ -H ‘Content-Type: application/json’ http://localhost:8080/api/user(存在问题)
curl -X POST -d ‘groupId=1’ -d ‘userType=1’ -d ‘userDetail=Tsinghua’ -d ‘createUser=Laiyigui’ -H ‘Content-Type: application/json’ http://localhost:8080/api/user(存在问题)
curl -X POST -d ‘groupId=1’ -d ‘{“groupId”:1,“userType”:1,“userDetail”:“Tsinghua”,“createUser”:“Laiyigui”}’ -H ‘Content-Type: application/json’ http://172.16.0.40:8080/api/user(存在问题)
curl -X POST -d ‘groupId=1’ -d “{”"“groupId”"":""“1"”",""“userType”"":""“1"”",""“userDetail”"":""“Tsinghua”"",""“createUser”"":""“Laiyigui”""}" -H ‘Content-Type: application/json’ http://localhost:8080/api/user(存在问题)
curl -X POST -F ‘filename=@User.xlsx’ --form ‘groupId=1’ -H ‘Content-Type: multipart/form-data’ http://localhost:8080/api/user/import //多类别参数上传
PUT
curl -X PUT -d ‘@user.json’ -H ‘Content-Type: application/json’ http://localhost:8080/api/user/124