How to decode http POST data in Java?

后端 未结 3 1287
臣服心动
臣服心动 2021-02-06 11:14

I\'m using Netty, and I\'ve got to accept and parse http POST requests. As far as I can tell, Netty doesn\'t have built-in support for POSTs, only GETs. (It\'s a fairly low-leve

3条回答
  •  孤城傲影
    2021-02-06 11:25

    You can use HttpPostRequestDecoder in Netty 4.x. It supports all kinds of POST body. Netty 4.x is marked as alpha at the moment, but very stable. See BodyParser in Xitrum.

    If you only need to parse simple body, you can still use QueryStringDecoder in Netty 3.x by treating the POST body like the part after "?" in URL, like this:

    QueryStringDecoder decoder = new QueryStringDecoder("?" +
        request.getContent.toString(org.jboss.netty.util.CharsetUtil.UTF_8));
    

提交回复
热议问题