Skip to content

Instantly share code, notes, and snippets.

@t3knoid
Created February 20, 2018 21:45
Show Gist options
  • Save t3knoid/f1ce4c1848915c194d0cb2538eb63a6b to your computer and use it in GitHub Desktop.
Save t3knoid/f1ce4c1848915c194d0cb2538eb63a6b to your computer and use it in GitHub Desktop.
Groovy example of printing groovy header fields after openConnection() call
def NEW_LINE = System.getProperty("line.separator")
if (args.length < 1)
{
println "Enter a URL as an argument."
System.exit(-1)
}
def address = args[0]
def urlInfo = address.toURL()
println "===================================================================="
println "====== HEADER FIELDS FOR URL ${address}"
println "===================================================================="
def connection = urlInfo.openConnection()
headerFields = connection.getHeaderFields()
headerFields.each {println it}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment