0

I have a request object.

I tried doing

 var str;
 for (var i in this.request)
 {
      str += i + "\n";
 }

And got: headers params response getClass equals query class hashCode wait uri pause resume endHandler bodyHandler notify path dataHandler method toString exceptionHandler notifyAll

Post parameters are nowhere to be found. Can anyone shed some light into this mistery ?

params() and headers() don't contain anything.

2 Answers2

6

Use a bodyHandler (here assuming you're posting JSON):

req.bodyHandler(function(data) {
  var postData = JSON.parse(data.toString());
});
Ludo
  • 76
  • 4
0

This can be done using the formAttributes on the http request. Here is an example in scala

  req.expectMultiPart(true) //Will expect a form
  req.endHandler({

    req.formAttributes() //This is used to access form attributes

    //some code with attributes

  })

Reference: http://vertx.io/core_manual_java.html#handling-multipart-form-attributes

Kevin Bayes
  • 846
  • 11
  • 17
  • This piece of code is throwing `Request has already been read` exception – Obaid Maroof Apr 05 '16 at 09:35
  • Should only happen if you have already read the request. This is a helper added in vertx 2 to assist with http forms. Code taken directly from a working project. Perhaps you can open another question with your exact problem? – Kevin Bayes Apr 07 '16 at 02:54