【发布时间】:2016-05-16 07:42:07
【问题描述】:
我有一个裸 sbt 项目,我添加了 "com.twitter" %% "finagle-http" % "6.33.0"。我正在关注 Twitter Finagle 的 quickstart 指南。我的代码是直接复制粘贴:
import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.http
import com.twitter.util.{Await, Future}
object Client extends App {
val client: Service[http.Request, http.Response] = Http.newService("www.scala-lang.org:80")
val request = http.Request(http.Method.Get, "/")
request.host = "www.scala-lang.org"
val response: Future[http.Response] = client(request)
response.onSuccess { resp: http.Response =>
println("GET success: " + resp)
println(resp.contentString) // modification 1
}
Await.ready(response)
println("needed this") // modification 2
}
没有“modification 2”我根本没有输出。加上println,我得到了
needed this
GET success: Response("HTTP/1.1 Status(200)")
Process finished with exit code 0
- 为什么不打印没有“
modification 2”的响应? - 为什么“
modification 1”没有打印出contentString?
如果我在“modification 1”上设置断点,并使用当前状态评估resp.contentString,则网站的 HTML 将根据需要返回。
如何在程序正常运行时打印?
【问题讨论】:
标签: scala http finagle twitter-finagle