我正在尝试下载我的 Facebook 个人资料图片。我成功地使用 oauth 来连接并获取所有正确的令牌,并被 facebook API 告知我的个人资料图片的 url。
但是,当我尝试检索它时,我收到有关无效 tls 的错误。我已经包含了一些显示我如何下载图像的 scala 代码。如果我更改为http,我可以得到它。但 https 失败。谁能建议为什么?我需要忽略 ssl 验证吗?
我在 build.sbt 中使用 net.databinder.dispatch %% dispatch-core % 0.11.2
scala> import dispatch.Defaults._
scala> import dispatch._
scala> import scala.concurrent.Await
scala> import scala.concurrent.duration._
scala> def fetchUrl( uri : String ) : Array[Byte] = {
| val svc = url(uri)
| val future_img = Http(svc OK as.Bytes)
| Await.result(future_img, Duration(10, "seconds"))
|
| future_img()
| }
fetchUrl: (uri: String)Array[Byte]
scala> fetchUrl("https://scontent-syd2-1.xx.fbcdn.net/v/t1.0-1/p200x200/12347856_10153070551591710_2899469599397194349_n.jpg?_nc_cat=105&_nc_sid=dbb9e7&_nc_ohc=1wqEuhGf4S4AX_iqRx5&_nc_ht=scontent-syd2-1.xx&tp=6&oh=4a792c1f0f4eded4ff2516efdfb056ab&oe=5F8D2DC4")
抛出关于无效 ss/tls 记录的异常
21:08:00.295 [New I/O worker #1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - Unexpected I/O exception on channel [id: 0xa80fd837, /10.0.0.16:59254 => scontent-syd2-1.xx.fbcdn.net/157.240.8.23:443]
org.jboss.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record:
如果我将 https 更改为 http,那么它可以工作。此外,如果我将 URI 粘贴到浏览器地址栏中,它会作为 https 工作并报告证书有效。
scala> fetchUrl("http://scontent-syd2-1.xx.fbcdn.net/v/t1.0-1/p200x200/12347856_10153070551591710_2899469599397194349_n.
jpg?_nc_cat=105&_nc_sid=dbb9e7&_nc_ohc=1wqEuhGf4S4AX_iqRx5&_nc_ht=scontent-syd2-1.xx&tp=6&oh=4a792c1f0f4eded4ff2516efdfb
056ab&oe=5F8D2DC4")
scala> fetchUrl("http://scontent-syd2-1.xx.fbcdn.net/v/t1.0-1/p200x200/12347856_10153070551591710_2899469599397194349_n.
jpg?_nc_cat=105&_nc_sid=dbb9e7&_nc_ohc=1wqEuhGf4S4AX_iqRx5&_nc_ht=scontent-syd2-1.xx&tp=6&oh=4a792c1f0f4eded4ff2516efdfb
056ab&oe=5F8D2DC4")
056ab&oe=5F8D221:08:53.263 [New I/O worker #3] DEBUG c.n.h.c.p.netty.NettyConnectionsPool - Adding uri: http://scontent-syd2-1.xx.fbcdn.net:80 for channel [id: 0xa499e1d5, /10.0.0.16:59341 => scontent-syd2-1.xx.fbcdn.net/157.240.8.23:80]
res1: Array[Byte] = Array(-1, -40, -1, -32, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, -1, -19, 0, -100, 80, 104, 111, 116, 111, 115, 104, 111, 112, 32, 51, 46, 48, 0, 56, 66, 73, 77, 4, 4, 0, 0, 0, 0, 0, -128, 28, 2, 103, 0, 20, 107, 111, 56, 50, 105, 103, 81, 77, 53, 57, 85, 55, 103, 73, 72, 45, 110, 119, 106, 75, 28, 2, 40, 0, 98, 70, 66, 77, 68, 48, 97, 48, 48, 48, 97, 56, 56, 48, 49, 48, 48, 48, 48, 99, 55, 48, 52, 48, 48, 48, 48, 102, 52, 48, 97, 48, 48, 48, 48, 49, 98, 48, 99, 48, 48, 48, 48, 53, 102, 48, 100, 48, 48, 48, 48, 57, 99, 49, 52, 48, 48, 48, 48, 99, 56, 49, 100, 48, 48, 48, 48, 55, 57, 49, 101, 48, 48, 48, 48, 98, 101, 49, 102, 48, 48, 48, 48, 49, 49, 50, 49, 48, 48, 48, 48, 54, 97, 51, 48, 48, 48, 48, 48, -1, -37, 0, 67, 0, 6, 4, 5, 6, 5, 4, 6, 6, 5, 6, 7, ...