Skip to content

Instantly share code, notes, and snippets.

@davidallsopp
Last active December 24, 2015 01:59
Show Gist options
  • Save davidallsopp/6727599 to your computer and use it in GitHub Desktop.
Save davidallsopp/6727599 to your computer and use it in GitHub Desktop.
Simple demo of checking HTTP proxy settings and/or downloading text or HTML pages in Scala, with equivalent code in Python for comparison
import scala.sys.SystemProperties
import scala.io.Source.fromURL
object ProxyTester extends App {
// Uncomment if you are behind a proxy, then edit the IP and port to match your proxy
// val props = new SystemProperties
//props("http.proxyHost") = "localhost"
//props("http.proxyPort") = "8080"
// Uncomment to see all the system properties including proxy settings
//props foreach println
println(fromURL("http://www.example.com").mkString)
// Equivalent in python (assuming appropriate import from urllib2)
// print urlopen('http://www.example.com').read()
// Or if you want to iterate over lines:
fromURL("http://www.example.com").getLines foreach println
// Near-equivalent in python (assuming appropriate import from urllib2)
// Reads in all data, rather than returning an iterator
// for line in urlopen('http://www.example.com/').readlines(): print line,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment