dongzouya5792 2015-09-29 15:07
浏览 238
已采纳

使用curl连接到Go RPC

I created a RPC server using the basic instructions listed here: https://golang.org/pkg/net/rpc/. I am building a application that might not be in Go to communicate with a RPC server and was curious how to manually connect to the server using curl or anything else.

I have tried:

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

but the output I get is:

* 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

This is mainly more to understand how to connect to it language agnostically, in the future I will most likely be using libraries from whatever language to communicate to the server.

Edit: for the above error, the url is actually localhost:1234/goRPC

But the question still remains to how to create a curl request that performs the same functionality as in the link https://golang.org/pkg/net/rpc/ that the client performs. How does the method call and arguments get serialized and placed in the CONNECT request

  • 写回答

1条回答 默认 最新

  • doutan1970 2015-10-01 23:16
    关注

    For anyone wondering, it is easier to use JSONRPC from the rpc/jsonrpc library and the curl request looks like:

    curl -X CONNECT --url <url>/_goRPC_ -d '{"method":"your rpc method","params":["args"],"id":<some number to represent your request>}'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!