追加したベア sbt プロジェクトがあり"com.twitter" %% "finagle-http" % "6.33.0"
ます。Twitter Finagleのクイックスタートガイドに従っています。私が持っているコードは直接コピーアンドペーストです:
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
ですか? contentString
「 」から印刷されないのはなぜmodification 1
ですか?
" " にブレークポイントを設定し、現在の状態を使用してmodification 1
評価resp.contentString
すると、Web サイトの HTML が期待どおりに返されます。
プログラムが正常に実行されている間にそれを印刷するにはどうすればよいですか?