Please ask in one spot at once, this question was answered on akka-user already, very quickly after it was asked. Please the ScalaDoc of
So you simply look into the Future before it had the chance to complete, so it's empty. Instead use operations like |
dear all:--I have written a akka http client example ,but I can not get whole HttpResponse body as a String , my code is below:import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpResponse, HttpRequest}
import akka.stream.ActorMaterializer
import scala.concurrent.duration._
import scala.util.{Failure, Success}
/**
* Created by luan on 8/26/16.
*/
object TestHttp {
def main(args: Array[String]) {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
//val url="http://cmdb.api.vip.com/webservice/domain_info/get_by_ip.do?name=bigdata-spark3-sd"
val url = "http://www.baidu.com"
println(url)
val responseFuture = Http().singleRequest(HttpRequest(uri = url))
var nodeCount: Int = 0
responseFuture.andThen {
case Success(resp: HttpResponse) => {
//println(resp.status.intValue())
//println(resp.status.defaultMessage())
//val aaaa = resp.entity.dataBytes.runFold(ByteString(""))(_ ++ _)
//println(aaaa.value.get.get.decodeString("UTF-8"))
//println(resp.entity.dataBytes.via(Framing.delimiter(ByteString("\n"),maximumFrameLength = 256,allowTruncation = true)).map(_.utf8String))
val entity = resp.entity.toStrict(5 seconds).map(_.data.decodeString("UTF-8"))
println(entity.value.getOrElse("none value"))
//nodeCount=JsonUtil.nodeCount(entity.value.get.get)
}
case Failure(ex:Exception) => {
println("http request error:"+ex.getMessage)
}
}
}
}and result is :who can tell me why ? and how to write the code?thanks very much
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.