[英]Receive params in jax-rs post method
我知道有關jaxrs params的問題已被問過很多次,並且對大多數事情都有很好的解釋。但是我找不到一個非常簡單的問題的答案。 我如何在請求后接收參數?
我的Jax-RS方法
@POST
@Path("data")
//@Consumes("application/json")
@Produces("application/json")
String getMobileServiceRepresentation(@PathParam("username") String username,@PathParam("password") String password) {
println username+":"+password
JSONObject obj=new JSONObject('{"dashboards": ["Dashbaord1","Dashboard2"]}')
obj
}
它輸出null:null
我的要求是通過curl
curl -X POST --data "username=username&password=pass" http://localhost:8080/blablaApp/api/mobileService/data
另外,我已經使用@Context UriInfo abc
來獲取所有上下文參數。 但沒有發現運氣
我想你應該使用@FormParam
注釋代替的@PathParam
一個在方法的參數。 當您要檢索請求URI的一部分時,使用@PathParam
。 對於您的情況,您想檢索請求正文內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.