简体   繁体   English

使用spray / scala从post请求中获取表单参数

[英]Get form parameters from a post request using spray/scala

I'm really new with all this Scala/Spray. 我对所有这些Scala / Spray都很新。 With some testing I was able to get parameters from a Get request using the parameters function. 通过一些测试,我可以使用参数函数从Get请求中获取参数。 However I'm trying to fetch some parameters sent from a POST request on the body of the request. 但是我正在尝试从请求正文的POST请求中获取一些参数。 It seems like parameters function is unable to fetch those values. 似乎参数函数无法获取这些值。

As an example, I'm trying to get this values "name=john&lastname=smith" from the post request body. 作为一个例子,我试图从post请求体中获取这个值“name = john&lastname = smith”。 What is the best option to get these values? 获得这些价值的最佳选择是什么?

Thank you 谢谢

You could use [Form-Field-Filters] to extract parameters from POSTs 您可以使用[Form-Field-Filters]从POST中提取参数

[Form-Field-Filters] https://github.com/spray/spray/wiki/Form-Field-Filters [Form-Field-Filters] https://github.com/spray/spray/wiki/Form-Field-Filters

Indeed, the parameters directive only handles things actually in the query-string and not parameters in the body of the request. 实际上, parameters指令仅处理查询字符串中的实际内容而不处理请求正文中的参数。 To get things out of the body, you'll need to use the content directive and then unmarshal the content. 要使事物脱离正常,您需要使用content指令然后解组内容。

This spray-user thread may be helpful, as it includes some unmarshalling code doing precisely what you're looking for. 这个喷涂用户线程可能会有所帮助,因为它包含一些解组代码,可以正确地执行您正在寻找的内容。

截至最近的Spray版本,您需要使用Unmarshaller for FormData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM