0

Sorry if this is a duplicate. I was looking for spark.RequestWrapper.getBody() on here and couldnt find what I was looking for. Basically, when I make a post request with 3 body values (name="Something, id="Something", someNumber=1) then call getBody(), I receive the following.

------WebKitFormBoundaryAFbSXBcWNVOAmQFo
Content-Disposition: form-data; name="name"

"Something"
------WebKitFormBoundaryAFbSXBcWNVOAmQFo
Content-Disposition: form-data; name="id"

"Something"
------WebKitFormBoundaryAFbSXBcWNVOAmQFo
Content-Disposition: form-data; name="someNumber"

1
------WebKitFormBoundaryAFbSXBcWNVOAmQFo--

I believe this actually comes from IOUtils.toByteArray(servletRequest.getInputStream()), and is cast to a string. Considering it's from servletRequest, I figured this is a pretty common problem, but haven't found a library or solution yet.

Thanks in advance for your help!

P.S. - If this is a duplicate, my apologies. Feel free to flag it and I'll be on my merry way!

Edit - Not Apache Spark. This one: http://sparkjava.com/

Brad Cypert
  • 671
  • 1
  • 8
  • 29

1 Answers1

-1

When you declare a route, you declare a parameter to access the request. Use this in order to get the request body, like request.body() or request.bodyAsBytes(), as it's done in the documentation. If you're still unable to get a better format, then you'll have to format it yourself in your client application. The best content-type to use for this would be application-json.

Laercio Metzner
  • 1,351
  • 11
  • 22