Jersey: Consume all POST data into one object

前端 未结 2 1617
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 00:14

I am using Jersey 1.8 in my application. I am trying to consume POST data at the server. The data is of the type application/x-www-form-urlencoded.

相关标签:
2条回答
  • 2021-01-06 00:18

    For cases where the Content-Type is multipart/form-data, this MultivaluedMap approach won't work.

    Use FormDataMultiPart - docs here.

    0 讨论(0)
  • 2021-01-06 00:35

    Got it. As per this document, I can use a MultivaluedMap<K,V> or Form to get all the POST data of the type application/x-www-form-urlencoded in one object. A working exmple:

        @POST
        @Path("/urienodedeample")
        @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
        @Produces(MediaType.APPLICATION_JSON)
        public Response uriEncodedExample(MultivaluedMap<String,String> multivaluedMap) {
            logger.info(multivaluedMap);
            return Response.status(200).build();
        }
    
    0 讨论(0)
提交回复
热议问题