I've got a Jersey REST server that responds to post requests like so:
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.AP开发者_StackOverflow中文版PLICATION_FORM_URLENCODED)
public String postHtml() {
I don't know ahead of time the names of all the parameters that might be sent to me. With a GET request I handle this like:
@Context
private UriInfo context;
@GET
@Produces(MediaType.TEXT_HTML)
public String getHtml() {
MultivaluedMap<String, String> queryParameters = context.getQueryParameters();
how can I do a similar thing with a POST request. I simply want to get all the parameters supplied in the post and I'll work with them in my code.
Turns out you can do:
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String postHtml(MultivaluedMap<String, String> inFormParams) {
If all your parameters are String type, which mine are. It would be good to know what to do if you have non-String parameters.
精彩评论