簡體   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