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>}'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分