Reputation: 6538
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
}}
Upvotes: 2
Views: 1068
Reputation: 14825
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
Upvotes: 1