Java 中的 JSON-RPC 客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5015479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSON-RPC client in Java
提问by Not Available
I'm trying to find a way to write a java application that can communicate with a json-rpc service (The service is a python twisted server).
我正在尝试找到一种方法来编写可以与 json-rpc 服务(该服务是 python 扭曲的服务器)通信的 Java 应用程序。
However I haven't been able to find a decent library with some good examples (I've googled and fiddled around for like 6 hours now).
但是我一直没能找到一个像样的图书馆和一些很好的例子(我已经用谷歌搜索并摆弄了大约 6 个小时)。
So are there any libraries for this in Java, or is there a more-cumbersome lower level way.
那么在 Java 中是否有任何用于此的库,或者是否有更麻烦的低级方法。
采纳答案by Luciano Fiandesio
You can take a look at Spring and the RestTemplate class (here is a good introduction: http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/).
你可以看看 Spring 和 RestTemplate 类(这里有一个很好的介绍:http: //blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/)。
Alternatively, you can use Commons HttpClientto post/get your Json payload to the service.
或者,您可以使用Commons HttpClient将您的 Json 负载发布/获取到服务。
PostMethod post = new PostMethod("http://myservice.com");
// add the payload to the post object
HttpClient client = new HttpClient();
int status = client.executeMethod(post);
String response = post.getResponseBodyAsString();
回答by Watsh Rajneesh
Check this out: https://code.google.com/p/json-rpc-client/
看看这个:https: //code.google.com/p/json-rpc-client/
The above is a JSON RPC client in Java that can talk to a JSON RPC Service.
以上是一个 Java 中的 JSON RPC 客户端,可以与 JSON RPC 服务对话。