如何使用akka-http进行HTTPS(非HTTP)请求?

时间:2015-07-02 13:54:04

标签: akka akka-http

我使用以下代码在Akka Actor中向akka-http库发出HTTP请求:

implicit val materializer = ActorFlowMaterializer()
implicit val system = context.system

val request = HttpRequest(HttpMethods.GET, "http://ya.ru")
val content = for {
  response <- Http().singleRequest(request)
  content <- Unmarshal(response.entity).to[String]
} yield content

一切正常,但现在我想发出HTTPS请求(只需将http://替换为https://)。之后,content变量将包含以下响应:

<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx</center>
</body>
</html>

似乎akka-http不支持HTTPS协议。使用akka-http发送HTTPS请求是正确还是可能?

1 个答案:

答案 0 :(得分:4)

如果查看official documentation,您会发现必须配置HTTPS上下文。然后它应该工作。