perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

FormData sent through XMLHttpRequest cannot be accessed with request.queryParams() #1123

Open IAbouzied opened 5 years ago

IAbouzied commented 5 years ago

I have a form that performs the following function in JS:

function makeNewSkill() {
    var formData = new FormData(document.querySelector('form'))
    var req = new XMLHttpRequest();
    req.open("post", url);
    req.send(formData);
}

I have confirmed that the form is sending data. On the Spark side, the data is reaching the server, but not in the queryParams (its empty). The only place I could find the data was in request.body(). When I run:

post("/myUrl") { req, res ->
     System.out.println(req.body());
}

I get:

------WebKitFormBoundaryIJmBMtLI7JX1Q8Cr
Content-Disposition: form-data; name="myData1"

myData1Value
------WebKitFormBoundaryIJmBMtLI7JX1Q8Cr
Content-Disposition: form-data; name="myData2"

myData2Value

Am I doing something wrong or are parameters not parsed if they are sent through an XMLHttpRequest with a Content-type of FormData?