我可以用什么在 Java 中创建 REST 客户端?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/868368/
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
What can I use to create a REST client in Java?
提问by jojo
Possible Duplicate:
Rest clients for Java?
可能的重复:
Java 的 Rest 客户端?
If I want to use Java to create a REST client, what should I use?
如果我想使用 Java 来创建 REST 客户端,我应该使用什么?
Can i use CXF?
我可以使用 CXF 吗?
采纳答案by Matthew Murdoch
I've had success using HttpClientfrom Jakarta Commons.
我使用Jakarta Commons 的HttpClient取得了成功。
Also Java comes with URLConnectionbut you might want to look at this comparisonwith HttpClient.
Java 也带有URLConnection,但您可能想看看这个与HttpClient 的比较。
Apache CXFdoes support REST clients (see here) but seems like overkill (CXF is a general 'services' framework and therefore complicated with support for CORBA, SOAP etc.)
Apache CXF确实支持 REST 客户端(请参阅此处),但似乎有点过分(CXF 是一个通用的“服务”框架,因此对 CORBA、SOAP 等的支持很复杂)
回答by Brian Agnew
There is a Jersey client APIthat allows you to easily implement clients in Java
有一个Jersey 客户端 API,可以让您轻松地在 Java 中实现客户端
回答by Vinnie
I used Restlet. I really liked it and wrote a blog postabout my experience.
回答by KingInk
imo there is hardly a need for a framework, simply use the servlet API and implement the request methods you need aka POST / GET / PUT / DELETE / HEAD
imo 几乎不需要框架,只需使用 servlet API 并实现您需要的请求方法,即 POST / GET / PUT / DELETE / HEAD
an example: http://www.exampledepot.com/egs/javax.servlet/com_mycompany_MyServlet.html
一个例子:http: //www.exampledepot.com/egs/javax.servlet/com_mycompany_MyServlet.html
回答by Alexander Torstling
I think it really depends on the app and your environment, but I find resteasyreally easy (since it is so declarative) and configurable. See chapter 30for the client documentation.
我认为这真的取决于应用程序和您的环境,但我发现resteasy真的很容易(因为它是如此声明性的)和可配置的。有关客户端文档,请参阅第 30 章。
回答by Atanas Roussev
Use HTTP4e REST clientadd-on for Eclipse. It is simple to use and has Java/C#/Ruby/Flex/ActionScript/etc.. one click code generation.
为 Eclipse使用HTTP4e REST 客户端插件。使用简单,有Java/C#/Ruby/Flex/ActionScript/etc..一键生成代码。
回答by R-JANA
I tried using examples given in this ling http://cxf.apache.org/docs/jax-rs-client-api.htmlI faced the problem that the Interface or the Impl may not be always avilable to client side to generate proxy. I also tried wadl2java to see if clients are generated. CXF 2.6 version did not create client class.
我尝试使用此 ling http://cxf.apache.org/docs/jax-rs-client-api.html 中给出的示例 我遇到了接口或 Impl 可能并不总是可供客户端生成代理的问题. 我还尝试了 wadl2java 来查看是否生成了客户端。CXF 2.6 版本没有创建客户端类。
I am happy with HTTPclient call till some concrete implementation changes ways to write client.
我对 HTTPclient 调用很满意,直到一些具体的实现改变了编写客户端的方式。
Note: We are using only CXF with Java thus only experimenting with CXF. other implementation may give different results
注意:我们仅将 CXF 与 Java 一起使用,因此仅尝试使用 CXF。其他实现可能会给出不同的结果

