为什么dispatch抛出“java.net.ConnectException:General SSLEngine ...”。和“意外状态”特定网址的例外情况? [英] Why does dispatch throw "java.net.ConnectException: General SSLEngine ..." and "unexpected status" exceptions for a particular URL?
本文介绍了为什么dispatch抛出“java.net.ConnectException:General SSLEngine ...”。和“意外状态”特定网址的例外情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下非工作代码:
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抛出异常。抛出的例外是:
I would like to know why "s1" works fine, whereas "s2" and "s3" throw exceptions. The exceptions thrown are:
例外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通过调度工作正常,但最后两个没有?
Also, all three URLs work as expected when I access them through the Safari web browser. Why does the first URL work fine through dispatch, but the last two don't?
推荐答案
如果你想信任所有证书,如在链接的Play示例中,然后尝试:
If you want to trust all certificates, as in the linked Play example, then try this:
Http.withConfiguration(config => config.setAcceptAnyCertificate(true))(url(address).GET OK as.String)
这篇关于为什么dispatch抛出“java.net.ConnectException:General SSLEngine ...”。和“意外状态”特定网址的例外情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文