为什么 dispatch 会针对特定的 URL 抛出 "java.net.ConnectException: General SSLEngine ..." 和 "unexpected status" 异常?

Why does dispatch throw "java.net.ConnectException: General SSLEngine ..." and "unexpected status" exceptions for a particular URL?

我有以下无效代码:

object Main extends App {
  import dispatch._

  def test(address: String) = {
    Await.result(Http.default(url(address).GET OK as.String), Duration.Inf)
  }

  // This works fine
  val s1 = test("http://download.finance.yahoo.com/d/quotes.csv?s=MSFT&f=sohgbav")
  println(s1)

  // This throws Exception 1
  val s2 = test("http://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo&datatype=csv")
  println(s2) 

  // This throws Exception 2
  val s3 = test("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo&datatype=csv")
  println(s3) 
}

我想知道为什么 "s1" 工作正常,而 "s2" 和 "s3" 抛出异常。抛出的异常是:

异常 1:

[error]   ! access URL
[error]    java.util.concurrent.ExecutionException: dispatch.StatusCode: Unexpected response status: 301 (NettyResponseFuture.java:172)
[error] org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:172)
[error] dispatch.HttpExecutor.$anonfun$apply(execution.scala:123) 

异常 2:

[error]   ! access URL
[error]    java.util.concurrent.ExecutionException: java.net.ConnectException: General SSLEngine problem (NettyResponseFuture.java:172)
[error] org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:172)
[error] dispatch.HttpExecutor.$anonfun$apply(execution.scala:123)

此外,当我通过 Safari 网络浏览器访问它们时,所有三个 URL 都按预期工作。为什么第一个 URL 通过调度工作正常,但最后两个却不行?

如果您想信任所有证书,如链接的 Play 示例中所示,请尝试以下操作:

Http.withConfiguration(config => config.setAcceptAnyCertificate(true))(url(address).GET OK as.String)

为了创建一个验证证书的 Http 客户端,我在这里找到了一些示例代码:https://kevinlocke.name/bits/2012/10/03/ssl-certificate-verification-in-dispatch-and-asynchttpclient/