{"id":3510,"date":"2016-03-27T23:40:21","date_gmt":"2016-03-27T23:40:21","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3510"},"modified":"2016-03-27T23:40:21","modified_gmt":"2016-03-27T23:40:21","slug":"scala-wgetcurl-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/scala-wgetcurl-example\/","title":{"rendered":"Scala: wget\/curl example"},"content":{"rendered":"<p>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.<\/p>\n<pre lang=\"scala\">\nval testUrl = \"https:\/\/\" + domain\nval url = new URL(testUrl)\nval conn: HttpsURLConnectionImpl = url.openConnection() match {\n  case httpsConn: HttpsURLConnectionImpl => httpsConn\n  case conn => {\n    println(conn.getClass)\n    ???\n  }\n}\n\n\/\/ Set any additional arguments here -\n\/\/ E.g. timeout, user agent, \"GET\" vs \"POST\"\n\/\/ prior to connect\nconn.connect()\n\nval certs = conn.getServerCertificateChain\n\nprintln(conn.getResponseCode)\nprintln(conn.getResponseMessage)\nprintln(conn.getContentLength)\nprintln(conn.getContent)\nprintln(conn.getContentType)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 = &#8220;https:\/\/&#8221; + domain val url = new URL(testUrl) val conn: HttpsURLConnectionImpl = url.openConnection() match { case httpsConn: HttpsURLConnectionImpl => httpsConn case conn => { println(conn.getClass) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/scala-wgetcurl-example\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Scala: wget\/curl example&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[132,279,300,480,495,596],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3510"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3510"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3510\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}