gpt4 book ai didi

curl - 使用 curl 连接到 Go RPC

转载 作者:IT王子 更新时间:2023-10-29 01:15:31 25 4
gpt4 key购买 nike

我使用此处列出的基本说明创建了一个 RPC 服务器:https://golang.org/pkg/net/rpc/ .我正在构建一个可能不在 Go 中与 RPC 服务器通信的应用程序,并且很好奇如何使用 curl 或其他任何方式手动连接到服务器。

我试过:

curl -v -X CONNECT --url localhost:1234/_goRPC

但我得到的输出是:

* Hostname was NOT found in DNS cache
* Trying ::1...
* Connected to localhost (::1) port 1234 (#0)
> CONNECT /_goRPC HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:1234
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< Date: Tue, 29 Sep 2015 15:04:29 GMT
< Content-Length: 19
<
404 page not found
* Connection #0 to host localhost left intact

这主要是为了了解如何与语言无关地连接到它,将来我很可能会使用来自任何语言的库来与服务器通信。

编辑:对于上面的错误,url其实是localhost:1234/goRPC

但问题仍然是如何创建执行与链接 https://golang.org/pkg/net/rpc/ 中相同功能的 curl 请求客户端执行的。方法调用和参数如何序列化并放置在 CONNECT 请求中

最佳答案

对于任何想知道的人,使用 rpc/jsonrpc 库中的 JSONRPC 更容易,curl 请求如下所示:

curl -X CONNECT --url <url>/_goRPC_ -d '{"method":"your rpc method","params":["args"],"id":<some number to represent your request>}'

关于curl - 使用 curl 连接到 Go RPC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32847561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com