为了账号安全,请及时绑定邮箱和手机立即绑定

JPOS Restful API 收发数据

JPOS Restful API 收发数据

鸿蒙传说 2022-12-15 15:26:07
我从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();    }}如何从客户端接收数据?没有请求参数,查找什么是请求及其数据;
查看完整描述

1 回答

?
杨魅力

TA贡献1811条经验 获得超6个赞

我将代码更改为:


    @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:

//img1.sycdn.imooc.com//639acc460001874606080514.jpg

查看完整回答
反对 回复 2022-12-15
  • 1 回答
  • 0 关注
  • 176 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号