我正在玩Akka Http客户端。我创建了一个简单的请求但是如何解组这个respose?在服务器端,很容易使用circe来编组响应,但我在客户端遇到困难
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.Uri.Query
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.Materializer
import scala.concurrent.ExecutionContext
class QuestionsFetcher {
import de.heikoseeberger.akkahttpcirce.CirceSupport._
import io.circe.generic.auto._
val baseUrl = "https://somewhere.com"
def fetch(tag: String)(implicit ac: ActorSystem, materializer: Materializer) = {
implicit val ec: ExecutionContext = ac.dispatcher
val fromDate = DateTime.now.minus(1000 * 60 * 60 * 24)
val uri = Uri(baseUrl).withQuery(Query("order"->"desc"))
val request = HttpRequest(HttpMethods.GET, uri)
Http().singleRequest(request)
.map(r => Unmarshal(r.entity.withContentType(ContentTypes.`application/json`)).to[Items])
} }
运行我得到的代码时 ErrorFuture(io.circe.ParsingFailure:期望的json值得到(第1行,第1列))
答案 0 :(得分:0)
内容被gziped - 所以在运行解码器流后 没关系