web-services - Web 服务调用上的 Scala Play2 错误

标签 web-services scala playframework playframework-2.0

使用以下代码进行编译时出现错误。 我正在尝试调用 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/

相关文章:

web-services - cfcomponent Web 服务 - 获取 SOAP 属性

scala - 如何在 Spark 1.5 中转置数据帧(没有可用的枢轴运算符)?

java - play框架中用户上传的文件放在哪里?

java - 玩!框架 : Layouts with different sections

Java Play 框架和 Python Django GAE

web-services - SOAP/REST Webservices XML 区分大小写

java - 从 JAX-WS 异步 Web 服务获取 HTTP 响应代码

MSBUILD 发布不发布 xsd 架构文件

scala - 将输入任务与 sbt 中的动态任务相结合

scala - 理解偏函数中的 'case'关键字