How to print HTTP request data in a Play Framework controller action

As a quick note to self, here’s how to just printed some HTTP request information in a Play Framework controller action:

def login = Action { implicit request =>
    println("*** ENTERED 'login' ACTION ***")
    println(s"    content-type: ${request.contentType}")
    println(s"    headers: ${request.headers}")
    println(s"    body: ${request.body}")
    println(s"    query string: ${request.rawQueryString}")

    ...
  
}

The rest of the code doesn’t matter, I just wanted to show how to access the request information in a Play controller action method.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.