Gerrit使用curl命令访问gerrit的REST API

版权声明:本文为博主原创文章,未经博主允许不得转载。 马哥私房菜的github地址 https://github.com/mageSFC/myblog https://blog.csdn.net/mmh19891113/article/details/82220538

简单的测试 reset api 可以像下面这样

  curl http://localhost:8080/path/to/api/

curl命令默认是发送GET请求的,可以通过选项 -X来设置

 curl -X GET http://localhost:8080/path/to/api/
 curl -X PUT http://localhost:8080/path/to/api/
 curl -X POST http://localhost:8080/path/to/api/
 curl -X DELETE http://localhost:8080/path/to/api/

curl命令发送请求同时带上数据,可以使用-d选项。

curl -X PUT -d@testdata.txt --header "Content-Type: application/json" http://localhost:8080/path/to/api/

不过-d选项会把内容中的换行移除。我还可以使用–data-binary 选项代替

curl -X PUT --data-binary @testdata.txt --header "Content-Type: text/plain" http://localhost:8080/path/to/api/

curl发送请求带上用户认证,也就是带上用户名密码

curl --digest --user username:password http://localhost:8080/a/path/to/api/
curl -X PUT --digest --user john:2LlAB3K9B0PF --data-binary @project-desc.txt --header "Content-Type: application/json; charset=UTF-8" http://localhost:8080/a/projects/myproject/description

我们也可以吧用户名密码存到 .netrc文件中 (Windows系统是这个_netrc文件):
curl --digest -n http://localhost:8080/a/path/to/api/
curl -v -n --digest -X DELETE http://localhost:8080/a/path/to/api/

猜你喜欢

转载自blog.csdn.net/mmh19891113/article/details/82220538