小编典典

为什么调度会针对特定URL抛出“ java.net.ConnectException:常规SSLEngine…”和“意外状态”异常?

java

我有以下无效代码:

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$3(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$3(execution.scala:123)

另外,当我通过Safari Web浏览器访问所有三个URL时,它们均按预期工作。为什么第一个URL可以通过分发正常运行,而后两个URL不能正常运行?


阅读 773

收藏
2020-11-26

共1个答案

小编典典

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

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