title: How to get the raw request body in Play?
body: <p>My play application has an endpoint for receiving webhooks from Stripe.</p>
  
  <p>In order to verify the webhooks, the request body needs to be compared against a signature and a signing key. This requires that I have access to the raw request body, as sent.</p>
  
  <p>However, it seems that Play alters the request body, and I can't get access to the raw contents. This causes the computed signature to change, and the verification fails. More info: <a href="https://stackoverflow.com/a/43894244/49153">https://stackoverflow.com/a/43894244/49153</a></p>
  
  <p>Here's my code:</p>
  
  <pre><code>@Singleton
  class WebhookController @Inject()(cc : ControllerComponents,
                                    env: Env)
                                   (implicit ec: ExecutionContext)
    extends AbstractController(cc) {
  
    private val log = Logger("WebhookController")
  
  
    def index(): Action[AnyContent] = Action.async { implicit req =&gt;
  
        val signature =
            req.headers.headers.find(_._1 == "Stripe-Signature").map(_._2).getOrElse("").trim
  
        if (verifySignature(req.body.toString, signature, env.webhookSecretKey))
          Future.successful(ok("ok"))
        else
            Future.successful(ok("Couldn't verify signature"))
    }
  
  
  }
  </code></pre>
  
  <p>Here I'm trying to access the body using <code>req.body.toString</code> but it looks to be the deserialized json rather than the raw body.</p>
  
  <p>Using <code>req.body.asRaw</code> returns a none.</p>
  
  <p>Any ideas?</p>