gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 17:26:22 27 4
gpt4 key购买 nike

我有以下无效代码:

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”抛出异常。抛出的异常是:

异常(exception)情况 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)

异常(exception) 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 网络浏览器访问所有三个 URL 时,它们都按预期工作。为什么第一个 URL 通过调度工作正常,但最后两个却不行?

最佳答案

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

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

关于java - 为什么 dispatch 会针对特定 URL 抛出 "java.net.ConnectException: General SSLEngine ..."和 "unexpected status"异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46301238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com