使用以下代码进行编译时出现错误。 我正在尝试调用 Web 服务。
def authenticate(username: String, password: String): String = {
val request: Future[Response] =
WS.url(XXConstants.URL_GetTicket)
.withTimeout(5000)
.post( Map("username" -> Seq(username), "password" -> Seq(password) ) )
request map { response =>
Ok(response.xml.text)
} recover {
case t: TimeoutException =>
RequestTimeout(t.getMessage)
case e =>
ServiceUnavailable(e.getMessage)
}
}
我看到以下编译器错误:
type mismatch; found : scala.concurrent.Future[play.api.mvc.SimpleResult[String]] required: String
最佳答案
从您的 authenticate
函数返回的值是 val request = ...
,其类型为 Future[Response]
但该函数需要一个 String
,正如编译器所说,这是一个类型不匹配错误。将函数的返回类型更改为 Future[Response]
或在返回之前将 request
转换为 String
应该可以修复该问题。
关于web-services - Web 服务调用上的 Scala Play2 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14209001/