JPOS Restful API 收发数据

我从jpos-rest.pdf在 JPOS 中配置 RESTFul API 。

问题是我无法从客户端接收数据,但我可以向客户端发送数据。

在Echo.java课堂上通过下面的代码我可以发送数据:


package org.jpos.rest;


import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

import javax.ws.rs.core.Response;

import java.util.HashMap;

import java.util.Map;


@Path("/echo")

public class Echo {

    @GET

    @Produces({MediaType.APPLICATION_JSON})

    public Response echoGet() {

        Map<String, Object> resp = new HashMap<>();

        resp.put("success", "true");

        resp.put("Name", "Hamid");

        resp.put("Family", "Mohammadi");

        Response.ResponseBuilder rb = Response.ok(resp, MediaType.APPLICATION_JSON).status(Response.Status.OK);

        return rb.build();

    }

}

http://img1.mukewang.com/639acc290001cde805420380.jpg

如何从客户端接收数据?没有请求参数,查找什么是请求及其数据;

鸿蒙传说
浏览 177回答 1
1回答

杨魅力

我将代码更改为:&nbsp; &nbsp; @Path("/echo")&nbsp; &nbsp; public class Echo {&nbsp; &nbsp; &nbsp; &nbsp; @PUT&nbsp; &nbsp; &nbsp; &nbsp; @Produces({MediaType.APPLICATION_JSON})&nbsp; &nbsp; &nbsp; &nbsp; @Consumes(MediaType.TEXT_PLAIN)&nbsp; &nbsp; &nbsp; &nbsp; @Path("/{name}/{family}")&nbsp; &nbsp; &nbsp; &nbsp; public Response echoGet(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @PathParam("name") String name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @PathParam("family") String family,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String Desc&nbsp; &nbsp; &nbsp; &nbsp; ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<String, Object> resp = new HashMap<>();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.put("success", "true");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.put("Name", name);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.put("Family", family);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.put("Desc", Desc);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.ResponseBuilder rb = Response.ok(resp,MediaType.APPLICATION_JSON).status(Response.Status.OK);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return rb.build();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }并像这样将数据发送到 RESTFul API:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java