Search code examples
scalaplayframeworkplayframework-2.3

WS - Setting string in request headers creates a list


Maybe the title isn't explicit enough.

I'm using scala PlayFramework 2.3, and WS library to send request to other websites.

My issue is that when I log

WS.url(url).withHeaders("OAuth-Token" -> token).headers()

I get

Map(OAuth-Token -> List("5ad12543-fed8-4df6-8830-c97030caee09"))

Which can't work because the token is set in a list despite the fact that token is a simple String.

Is there a way to do something whithout upgrading Play's version or even some hack with WS library ?


Solution

  • So I finally resolved it. The problem was that in my header it was :

    OAuth-Token: "5ad12543-fed8-4df6-8830-c97030caee09"
    

    The quotes have no reason to be here.

    When I parsed the json data of token, I did :

    val token = (res.json.as[JsObject] \ "access_token").toString()
    

    It should have been :

    val token = (res.json.as[JsObject] \ "access_token").as[String]