grpcurl 的使用

grpcurl 是一個多平臺可以用的,可以發(fā)送grpc請求到服務器的客戶端工具,可以用于grpc服務器的各種測試和debug

可以在官方Git下載安裝

列出一個grpc servert提供的所有服務(如果服務器沒有添加TLS證書,需要使用-plaintext參數(shù))

grpcurl -plaintext localhost:6565 list

帶參數(shù)請求,參數(shù)必須放在host地址前

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

請求時參數(shù)的順序并不一定要跟proto文件中設定的一致,參數(shù)名一致了就行
此處-d后面跟的必須是單個positional argument,如果使用windows的cmd和powershell,可能會產(chǎn)生各種解析問題,以下為powershell的正確范例

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

使用參數(shù)-authority可以假裝請求server為另一個,從而通過證書校驗,在測試環(huán)境很管用

> 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"
}
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容