繁体   English   中英

Sending POST request with POSTMAN to Java REST API and getting null values in the xml response

[英]Sending POST request with POSTMAN to Java REST API and getting null values in the xml response

I am creating a REST Service in Java and now I am building the post method wich has 2 parameters that has to be inputted as xml in postman (for test) and get a response as xml in java and insert it in database.

对于初学者,我试图将值作为查询参数添加到 POSTMAN 中,并带有键和值。 响应为 200,但 xml 为 CUI=null Mesaj=null

即使您在 Postman 中为两个键添加了值,这两个值都是 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 中的帖子中发送的参数值?

提前致谢

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

正确: /cererepost/some_value

如果要将它们作为服务器端的查询字符串参数获取, @PathParam("cui")更改为@QueryParam("cui")

要了解query stringpath variables之间的区别,请查看这篇文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM