首页 > 解决方案 > 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();
    }
}

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

标签: javaapirestful-urljpos

解决方案


感谢@Sabir Khan,我将代码更改为:

    @Path("/echo")
    public class Echo {
        @PUT
        @Produces({MediaType.APPLICATION_JSON})
        @Consumes(MediaType.TEXT_PLAIN)
        @Path("/{name}/{family}")
        public Response echoGet(
                @PathParam("name") String name,
                @PathParam("family") String family,
                String Desc
        ) {
            Map<String, Object> resp = new HashMap<>();
            resp.put("success", "true");
            resp.put("Name", name);
            resp.put("Family", family);
            resp.put("Desc", Desc);
            Response.ResponseBuilder rb = Response.ok(resp,
MediaType.APPLICATION_JSON).status(Response.Status.OK);
            return rb.build();
        }
    }

并将数据发送到 RESTFul API,如下所示: 这个


推荐阅读