2

I am using WS to call distant api. The answer is formatted as a byte array. How do I parse the body of a WSResponse as a byte array ? I don't want to use the boilerplate getStream.

val holder: WSRequestHolder = WS.url(url)
  .withRequestTimeout(requestTimeout)
  .withHeaders(HeaderNames.ACCEPT -> ContentTypes.BINARY)
holder.get() map { response => response.status match {
  case 200 => response.bodyAsBytes // I am looking for the bodyAsBytes function
}}
Moebius
  • 6,242
  • 7
  • 42
  • 54

1 Answers1

1

Get the body of the response in string format and then convert it into bytes with appropriate format

response.body.toString.getBytes(Charset.forName("UTF-8"))

Also look at Convert string to bytes

Community
  • 1
  • 1
Nagarjuna Pamu
  • 14,737
  • 3
  • 22
  • 40