英文:
How to curl a POST endpoint with a protobuf payload
问题
我有一个Java服务中的POST端点,它期望一个Protobuf 3负载。其他服务使用这个服务发送Protobuf负载。我想要做一些调试,并通过curl
命令发送一个Protobuf负载到该服务,然而,我不知道如何构造这样的负载,因为它是一个二进制协议。
英文:
I have a POST endpoint in my Java service that expects a protobuf 3 payload. This service is used by other services which send the protobuf payload. I would like to do some debugging and send a protobuf payload to the service via a curl
command, however, I have no idea how to construct such a payload, given it's a binary protocol.
答案1
得分: 2
你可以使用 protoCURL 来实现这个目的。它是一个命令行工具,用于发送和接收 Protobuf HTTP REST 请求,同时将它们编写成 Protobuf Text 或 JSON 格式。
一个请求可能看起来像这样:
protocurl -I path/to/protos -i ..MyRequest -o ..MyResponse \
-u http://host/path/o/endpoint -d 'someField: "some-string", someIntField: 42'
响应可能如下所示:
=========================== Request Text =========================== >>>
someField: "my-string"
someIntField: 42
=========================== Response Text =========================== <<<
someResponseField: "The answer for everything!"
someOtherResonseMessage: {
fooEnum: BAR
}
你可以在 repository 中找到更多使用示例。
(免责声明:我是这个工具的作者,因为我遇到了相同的问题并需要一个更好的工具才创建了它。)
英文:
You can use protoCURL for this purpose. It's a command-line tool to send and receive protobuf HTTP REST requests while writing them in the Protobuf Text or JSON format.
A request could look something like this:
protocurl -I path/to/protos -i ..MyRequest -o ..MyResponse \
-u http://host/path/o/endpoint -d 'someField: "some-string", someIntField: 42'
And the response may look like this:
=========================== Request Text =========================== >>>
someField: "my-string"
someIntField: 42
=========================== Response Text =========================== <<<
someResponseField: "The answer for everything!"
someOtherResonseMessage: {
fooEnum: BAR
}
You can find more examples for how to use it in the repository.
(Disclaimer: I am the author of this tool and created it, because I had the same problem and needed a better tool.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论