各位,我是爪哇RESTful的新手,
我需要将数据从我的java应用程序传递到RESTful服务。我能够将RESTful添加到我的应用程序中,但无法将任何数据发送回服务。
我在服务中使用了“获取”和“消费”。请帮助我获得连接和数据交换之间的相同
当RESTful在我的应用程序中充当服务器时
RESTful定义
@GET
@Consumes("application/json")
@Path("{strID}")
public String getJson(@PathParam("strID")String strID){
return strID;
}进口RESTful法
public String getJson(String strID) throws UniformInterfaceException {
WebResource resource = webResource;
resource = resource.path(java.text.MessageFormat.format("{0}", new Object[]{strID}));
return resource.get(String.class);
}在java应用程序中
static RESTful objRFIDService = new RESTful();
objRFIDService.getJson("RESTfultest");发布于 2016-04-13 08:02:34
你想要达到的目标并不是很清楚。但是,要使用REST can服务,可以使用JAX客户端API,它是JAX-RS 2.0规范的一部分,参考实现是泽西岛。
例如,要对可用的GET资源执行http://example.com/api/foo/{id}请求,可以使用以下代码:
String id = ...
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://example.com").path("api").path("foo").path(id);
String result = target.request(MediaType.APPLICATION_JSON_TYPE).get(String.class);有关更多细节,请查看泽西客户端API文档。
https://stackoverflow.com/questions/36590211
复制相似问题