Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
akka http客户端跟随重定向_Akka_Akka Http - Fatal编程技术网

akka http客户端跟随重定向

akka http客户端跟随重定向,akka,akka-http,Akka,Akka Http,akka http文档提供了查询http服务的示例: 我如何告诉akka http自动遵循重定向,而不是接收代码==302的HttpResponse akka 2.5.3,akka http 10.0.9 import akka.actor.{ Actor, ActorLogging } import akka.http.scaladsl.Http import akka.http.scaladsl.model._ import akka.stream.{ ActorMaterializer,

akka http文档提供了查询http服务的示例:

我如何告诉akka http自动遵循重定向,而不是接收代码==302的HttpResponse

akka 2.5.3,akka http 10.0.9

import akka.actor.{ Actor, ActorLogging }
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.stream.{ ActorMaterializer, ActorMaterializerSettings }
import akka.util.ByteString

class Myself extends Actor
  with ActorLogging {

  import akka.pattern.pipe
  import context.dispatcher

  final implicit val materializer: ActorMaterializer = ActorMaterializer(ActorMaterializerSettings(context.system))

  val http = Http(context.system)

  override def preStart() = {
    http.singleRequest(HttpRequest(uri = "http://akka.io"))
      .pipeTo(self)
  }

  def receive = {
    case HttpResponse(StatusCodes.OK, headers, entity, _) =>
      entity.dataBytes.runFold(ByteString(""))(_ ++ _).foreach { body =>
        log.info("Got response, body: " + body.utf8String)
      }
    case resp @ HttpResponse(code, _, _, _) =>
      log.info("Request failed, response code: " + code)
      resp.discardEntityBytes()
  }

}

您不能告诉Akka http客户端自动执行此操作。这是Akka项目的一个公开问题:

您可以通过以下方式手动处理此问题:

case resp@HttpResponseStatusCodes.Redirection_u,u,u,u,u,headers,u,=> //从标头中提取位置,然后使用另一个pipeTo重试请求
您可能希望保持重定向次数的计数,以避免无限循环。

您不能告诉Akka http客户端自动执行此操作。这是Akka项目的一个公开问题:

您可以通过以下方式手动处理此问题:

case resp@HttpResponseStatusCodes.Redirection_u,u,u,u,u,headers,u,=> //从标头中提取位置,然后使用另一个pipeTo重试请求 您可能希望保持重定向次数的计数,以避免无限循环