如何从Jetty AbstractHandler handle()方法中检索POST数据?

时间:2014-09-10 22:03:07

标签: java rest post jetty

搜索了相当多的内容,但没有看到任何与我的特定情况/问题相符的帖子。

使用Jetty,我有一个扩展org.eclipse.jetty.server.handler.AbstractHandler的Handler类。

handle方法如下:

@Override
    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
                       throws IOException, ServletException {

我需要获取请求中发送的POST数据,就好像这样:

curl -H "Content-Type: application/json" -d '{"url":"http://www.example.com"}' http://localhost:8080/

基本上,我正在向我的localhost发送一个POST请求,其中一个JSON字典键入'url'。如何检索POST数据?

1 个答案:

答案 0 :(得分:5)

使用Handler.handle()方法中HttpServletRequest参数提供的标准servlet功能。

HttpServletRequest有两种方法可以访问请求正文。

然后使用标准的java IO技术来使用其中任何一个。