开发者

how to process variable numbers of parameters for jersey post requests

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜