0

我想記錄使用org.apache.http.client製作的帖子的正文。我正在使用Scalatra版本2.4.0.RC3和Scala版本2.11.7。我的回覆是一個400錯誤的請求,我需要獲取響應正文中提供的消息。斯卡拉ByteArrayInputStream字符串

這裏是我當前的代碼:

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

response.getEntity()的getContent()打印:

[email protected] 

我需要得到實際的身體從這個ByteArrayInputStream的字符串。

回答

1

您可以使用EntityUtils形成相同的庫:

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