我有這種簡單的測試Scala的應用Scala的獨立應用程序,其中的阻擋http請求:如何有使用playframework庫
build.sbt
name := "hello"
version := "1.0"
scalaVersion := "2.11.2"
libraryDependencies += "com.typesafe.play" %% "play-ws" % "2.4.0-M1"
Test.scala
import play.api.libs.json._
import play.api.libs.ws._
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
object Test {
def main(args: Array[String]) = {
val wsClient = WS.client
val body = getBody(wsClient.url("http://example.com/").get())
println(s"body: $body")
}
def getBody(future: Future[WSResponse]) = {
val response = Await.result(future, Duration.Inf);
if (response.status != 200)
throw new Exception(response.statusText);
response.body
}
}
此應用程序失敗: 線程「main」中的異常java.lang.RuntimeException:沒有啓動的應用程序
如何解決這個問題?
如何做到這一點最明顯的例子是我見過,謝謝Will。 – 2015-02-23 17:01:50
全部現已在2.5.x版中棄用。 – ses 2016-09-20 01:26:22
您好@ses - 請參閱https://www.playframework.com/documentation/2.5.x/ScalaWS#using-wsclient和https://www.playframework.com/documentation/2.5.x/ScalaTestingWebServiceClients – 2016-09-20 01:41:59