Jeremy Wagner
Jeremy Wagner

Reputation: 515

Scala ByteArrayInputStream to String

I'm trying to log the body of a post made using org.apache.http.client. I'm using Scalatra version 2.4.0.RC3 and Scala version 2.11.7. My response is a 400 Bad Request and I need to get the message provided in the response body.

Here is my current code:

val response = client.execute(post)
println(response)
println(response.getEntity().getContent())

response.getEntity().getContent() prints:

java.io.ByteArrayInputStream@1q232e4e

I need to get the actual body as string from this ByteArrayInputStream.

Upvotes: 0

Views: 887

Answers (1)

JP1225170887752
JP1225170887752

Reputation: 591

You can use EntityUtils form the same library:

import org.apache.http.util.EntityUtils;
println(EntityUtils.toString(response.getEntity()));

Upvotes: 1

Related Questions