Is it possible to get POST parameters from REST request?
I tried the following with no success:
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
log.info("Params Size: "+params.size());
Iterator<String> it = params.keySet().iterator();
String theKey = null;
while(it.hasNext()){
theKey = it.next();
log.info("Here is a Key: "+theKey);
}
Here is my method signature:
@POST
@Produces("application/pdf")
@Path("/hello")
public Response producePDF(@FormParam("filename")String fileName, @Context UriInfo uriInfo)
Logs show 0 for "Params Size:"
Can I only use a GET?
@Roman Vottner Your answer was it. I needed to inject the MultivaluedMap instead of constructing at method call.
Code:
@POST
@Produces("application/pdf")
@Path("/hello")
@Consumes("application/x-www-form-urlencoded")
public Response producePDF(MultivaluedMap<String, String> params)
Iterator<String> it = params.keySet().iterator();
String theKey = null;
while(it.hasNext()){
theKey = it.next();
log.info("Here is a Key: "+theKey);
if(theKey.equals("filename")){
fileName = params.getFirst(theKey);
System.out.println("Key: "+theKey);
}
}
I can now get the parameters!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句