curl的使用

参考链接:
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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值