使用POSTMAN将POST请求发送到Java REST API并在xml响应中获取空值

问题描述 投票:0回答:1

[我正在用Java创建REST服务,现在我正在构建具有2个参数的post方法,该方法必须在postman中作为xml输入(用于测试),并在Java中获得xml作为响应并将其插入数据库中。] >

对于初学者,我正在尝试使用键和值将值添加为POSTMAN中的查询参数。响应为200,但xml为CUI = null Mesaj = null

即使您在邮递员中为两个键都添加了值,两个值都为空。

它怎么看这些值?这是java代码:

@Stateless
@Path("/cererepost")
public class HelloWorldResource {
Resp x = new Resp();
@EJB
private NameStorageBean nameStorage;
/**
 * Retrieves representation of an instance of    helloworld.HelloWorldResource
 * @return an instance of java.lang.String
 */
@POST
@Produces("application/xml")
@Consumes(MediaType.APPLICATION_XML)
public Response postMsg(@PathParam("cui") String cui,    @PathParam("mesaj") String mesaj)  {



    String xmlString = "CUI=" + cui + " Mesaj=" + mesaj;
    Response response = Response.status(200).type(MediaType.TEXT_XML).entity(xmlString).build();
    return response;

}

}

我应该修改什么,以便可以在postman生成的xml中看到我在帖子中发送的参数值?

提前感谢

我正在用Java创建REST服务,现在我正在构建具有2个参数的post方法,该方法必须在postman中作为xml输入(用于测试),并在Java中获得xml作为响应并将其插入到...

java xml rest api postman
1个回答
0
投票

@PathParam("cui") String cui此行显示客户端的值应作为路径参数而不是查询字符串传递,如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.