0

抱歉,如果这是重复的。我在这里寻找 spark.RequestWrapper.getBody() 但找不到我要找的东西。基本上,当我使用 3 个正文值 (name="Something, id="Something", someNumber=1) 发出帖子请求然后调用getBody()时,我会收到以下信息。

------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--

我相信这实际上来自IOUtils.toByteArray(servletRequest.getInputStream()),并被转换为字符串。考虑到它来自 servletRequest,我认为这是一个很常见的问题,但还没有找到库或解决方案。

在此先感谢您的帮助!

PS - 如果这是重复的,我很抱歉。随意标记它,我会在我的快乐路上!

编辑 - 不是 Apache Spark。这个:http ://sparkjava.com/

4

1 回答 1

0

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.

于 2015-12-18T00:18:19.133 回答