【问题标题】:Akka HTTP Client EntityStreamSizeExceptionAkka HTTP 客户端 EntityStreamSizeException
【发布时间】:2019-04-11 00:24:27
【问题描述】:

我正在尝试使用 Akka HTTP 向我的本地主机发送一个 get 请求,但出现以下异常:

EntityStreamSizeException: actual entity size (Some(10166731700)) exceeded content length limit (8388608 bytes)! You can configure this by setting akka.http.[server|client].parsing.max-content-length or calling HttpEntity.withSizeLimit before materializing the dataBytes stream.)

基本上,我尝试请求的本地主机上的文件非常大。

我尝试使用withoutSizeLimit 解决它,但它不起作用:

val request = Get("http://localhost:8080/oa-ok.ntriples")
val limitedRequest = request.withEntity(request.entity.withoutSizeLimit())
val responseFuture = Http().singleRequest(limitedRequest)

我也尝试使用withSizeLimit,但没有帮助。有什么想法吗?

【问题讨论】:

    标签: scala akka akka-stream akka-http


    【解决方案1】:

    在响应实体上使用withoutSizeLimit,而不是在请求实体上。例如:

    val responseFuture: Future[HttpResponse] =
      Http().singleRequest(HttpRequest(uri = "http://localhost:8080/oa-ok.ntriples"))
    
    val responseSource: Source[ByteString, NotUsed] =
      Source.fromFuture(responseFuture)
        .flatMapConcat(_entity.withoutSizeLimit.dataBytes)
    

    responseSource 是响应实体的 Akka Streams Source

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      • 2018-01-04
      • 2017-12-22
      • 2018-02-16
      • 2016-10-24
      相关资源
      最近更新 更多