使用 Java 使用 RESTful API

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3262202/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:49:53  来源:igfitidea点击:

Consuming RESTful APIs using Java

javaapirest

提问by Gaurav Dadhania

How would you consume a RESTful API using Java with probably just the standard packages? For ex: Twitter API. I know there are great Java libraries to access it, but how would you start from scratch?

您将如何使用 Java 和标准包来使用 RESTful API?例如:Twitter API。我知道有很多很棒的 Java 库可以访问它,但是您将如何从头开始?

回答by James Khoo

Well, there are many ways you could access RESTful API using Java third party libraries, like using Apache Http Clientor using Sun Jersey API.

嗯,您可以通过多种方式使用 Java 第三方库访问 RESTful API,例如使用 Apache Http Client或使用Sun Jersey API

You could also use the native java.net.HttpURLConnection to consume REST Services

您还可以使用本机 java.net.HttpURLConnection 来使用 REST 服务

回答by bhagyas

Don't think you should start from scratch, however Spring's RestTemplate is something you can simple use to consume RESTful Services.

不要认为您应该从头开始,但是 Spring 的 RestTemplate 是您可以简单使用的东西来使用 RESTful 服务。

http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/

http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/

Cheers.

干杯。