Searched SO quite a bit, but didn't see any posts that seemed to match my particular situation/question.
Using Jetty, I have a Handler class extending org.eclipse.jetty.server.handler.AbstractHandler.
The handle method is as follows:
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
I need to grab the POST data sent in the request, as if like this:
curl -H "Content-Type: application/json" -d '{"url":"http://www.example.com"}' http://localhost:8080/
Basically, I'm sending a POST request to my localhost with a JSON dictionary keyed on 'url'. How can I retrieve that POST data?
Use the standard servlet features available to from the HttpServletRequest
parameter in the Handler.handle()
method.
The HttpServletRequest
has 2 methods that have access to the request body.
HttpServletRequest.getReader()
HttpServletRequest.getInputStream()
Then just use either of those 2 using standard java IO techniques.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With