调用getParameter()`
时,我有以下代码始终返回nullimport javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import javax.ws.rs.Path;
@Path("/path")
public class MyResource {
protected ResponseBuilder response;
protected HttpServletRequest request;
public MyResource(@Context HttpServletRequest request) {
this.request = request;
this.response = Response.ok();
}
@POST
public Response postTest() {
JSONObject responseObj = new JSONObject();
String test = request.getParameter("test");
log.debug(test);
return response.entity(responseObj.toString()).build();
}
}
我正在使用此卷曲触发它:
curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: b7a3801f-b9d7-c7a1-004e-ac70b835d436" -H "Content-Type: application/x-www-form-urlencoded" -d 'test=12345' 'http://localhost:8180/path'
我做错了什么?
答案 0 :(得分:0)
感谢您的帮助。
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import javax.ws.rs.Path;
@Path("/path")
public class MyResource {
protected ResponseBuilder response;
protected HttpServletRequest request;
public MyResource(@Context HttpServletRequest request) {
this.request = request;
this.response = Response.ok();
}
@POST
public Response postTest(@FormParam("test") String test) {
JSONObject responseObj = new JSONObject();
log.debug(test);
return response.entity(responseObj.toString()).build();
}
}