如果 header 缺少内容类型,如何通过 asText 在 scala play 中访问请求 body

How to access request body in scala play via asText if header is missing content type

我的播放应用程序中的传入请求没有设置 content-type headers 属性。这使得通过

访问 body
request.body.asText

有问题,因为自动解析似乎只提供 body via

request.body.asRaw

如何处理丢失的 content-type 属性,以便仍然能够通过“.asText”访问 body(假设它可以解析)

tolerantText body 解析器将忽略内容类型 headers:

object MyController extends Controller {

  def action = Action(parse.tolerantText) { req => 
    val text = req.body
    ...
  }
}