我正在嘗試向Pusher api發送一個請求,但我無法返回正確的類型,我類型不匹配;實測值:scala.concurrent.Future [play.api.libs.ws.Response]需要:play.api.libs.ws.Response類型不匹配;發現:scala.concurrent.Future [play.api.libs.ws.Response]必需:play.api.libs.ws.Response
def trigger(channel:String, event:String, message:String): ws.Response = {
val domain = "api.pusherapp.com"
val url = "/apps/"+appId+"/channels/"+channel+"/events";
val body = message
val params = List(
("auth_key", key),
("auth_timestamp", (new Date().getTime()/1000) toInt),
("auth_version", "1.0"),
("name", event),
("body_md5", md5(body))
).sortWith((a,b) => a._1 < b._1).map(o => o._1+"="+URLEncoder.encode(o._2.toString)).mkString("&");
val signature = sha256(List("POST", url, params).mkString("\n"), secret.get);
val signatureEncoded = URLEncoder.encode(signature, "UTF-8");
implicit val timeout = Timeout(5 seconds)
WS.url("http://"+domain+url+"?"+params+"&auth_signature="+signatureEncoded).post(body
}
在99%的情況下,您不應該等待異步。與未來一起工作的所有必要工具在框架中都是不可分割的。 –
這不是你正在尋找的解決方案... –
感謝Marius和Julien,你是對的,這會導致阻塞響應 – flubba