我使用play-ws standalone来在
scala中使用REST服务.
@H_404_2@val data = Json.obj("message" -> "How are you?")
wsClient.url("http://localhost:5000/token").post(data).map { response =>
val statusText: String = response.statusText
println(response.body)
}
当我运行这个时,我得到以下错误,
@H_404_2@Cannot find an instance of play.api.libs.json.JsObject to WSBody. Define a BodyWritable[play.api.libs.json.JsObject] or extend play.api.libs.ws.ahc.DefaultBodyWritables wsClient.url("http://localhost:5000/token").post(data).map { response =>它告诉定义一个bodywritable.我已阅读文档,但没有得到“BodyWritable”.我是斯卡拉的新手.请有人帮帮我.提前致谢.
解决方法
您需要为json对象导入BodyWritables,将以下import语句添加到源文件中
@H_404_2@import play.api.libs.ws.JsonBodyReadables._
import play.api.libs.ws.JsonBodyWritables._
有关更多信息,请查看official documentation