grpcurl 的使用

grpcurl 是一个多平台可以用的,可以发送grpc请求到服务器的客户端工具,可以用于grpc服务器的各种测试和debug

可以在官方Git下载安装

列出一个grpc servert提供的所有服务(如果服务器没有添加TLS证书,需要使用-plaintext参数)

grpcurl -plaintext localhost:6565 list

带参数请求,参数必须放在host地址前

grpcurl -d '{"first_name":"Tom","last_name":"Willson"}' -plaintext localhost:6565 list

请求时参数的顺序并不一定要跟proto文件中设定的一致,参数名一致了就行
此处-d后面跟的必须是单个positional argument,如果使用windows的cmd和powershell,可能会产生各种解析问题,以下为powershell的正确范例

> grpcurl -d '{\"first_name\":\"Tom\",\"last_name\":\"Willson\"}' -plaintext localhost:6565 UserVerifyService/sayHello
{
  "message": "Hello Tom Willson"
}

使用参数-authority可以假装请求server为另一个,从而通过证书校验,在测试环境很管用

> grpcurl -d '{\"first_name\":\"Tom\",\"last_name\":\"Willson\"}' localhost:6565 UserVerifyService/sayHello
Failed to dial target host "localhost:6565": x509: certificate is valid for mila.lab, not localhost
> grpcurl -d '{\"first_name\":\"Tom\",\"last_name\":\"Willson\"}' -authority='mila.lab' localhost:6565 UserVerifyService/sayHello
{
  "message": "Hello Tom Willson"
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容