The following example shows how to implement the bones of a wget or curl style application in Scala, including checking for HTTPS and obtaining the certificate chain.
val testUrl = "https://" + domain
val url = new URL(testUrl)
val conn: HttpsURLConnectionImpl = url.openConnection() match {
case httpsConn: HttpsURLConnectionImpl => httpsConn
case conn => {
println(conn.getClass)
???
}
}
// Set any additional arguments here -
// E.g. timeout, user agent, "GET" vs "POST"
// prior to connect
conn.connect()
val certs = conn.getServerCertificateChain
println(conn.getResponseCode)
println(conn.getResponseMessage)
println(conn.getContentLength)
println(conn.getContent)
println(conn.getContentType)