首页 > 解决方案 > 如何向 gRPC-JSON 转码器端点提交请求?

问题描述

按照这个(我认为准确): https ://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/grpc_json_transcoder_filter

我正在遵循文档中的配置,并且我的 gRPC 服务已打开:50051,并且 gRPC-JSON 转码器正在侦听:51051.

我能够针对转码器提交 gRPC 请求:

grpcurl \
--plaintext \
--import-path=${HELLOWORLD} \
--import-path=${GOOGLEAPIS} \
--proto=helloworld/helloworld.proto \
-d '{"name":"Freddie"}' \
:51051 \
helloworld.Greeter/SayHello
{
  "message": "Hello Freddie"
}

但我无法确定如何正确提交 REST 请求:

curl \
--request GET \
--header "Content-Type: application/json" \
--data '{"name":"Freddie"}' \
http://0.0.0.0:51051/helloworld.Greeter/SayHello

curl \
--header "Content-Type: application/json" \
--data '{"name":"Freddie"}' \
http://0.0.0.0:51051/say

curl \
--request GET \
--header "Content-Type: application/json" \
http://0.0.0.0:51051/say?name=Freddie

我尝试过使用|不使用标题,使用--insecure和https,使用--request POST--request GET所有都没有成功。

所有结果:

upstream connect error or disconnect/reset before headers. reset reason: remote reset

也希望获得有关调试此类问题的指导。Envoy 没有将任何与这些请求对应的标准输出记录到标准输出中,并且管理控制台也没有包含(明显的)解释。

谢谢!

标签: grpcenvoyproxy

解决方案


嗯...我在另一台机器上重新制作了解决方案,它可以工作:

工作变体:

curl \
--header "Content-Type: application/json" \
http://localhost:51051/say?name=Frederik
{
 "message": "Hello Frederik"
}

curl http://localhost:51051/say?name=Frederik
{
 "message": "Hello Frederik"
}

非工作(不正确)变体:

curl \
--header "Content-Type: application/grpc" \
http://localhost:51051/say

curl \
--data '{"name":"Henry"}' \
http://localhost:51051/say
upstream connect error or disconnect/reset before headers. reset reason: remote reset

推荐阅读