Skip to content

Instantly share code, notes, and snippets.

@tuolumne
Created January 28, 2014 00:27
Show Gist options
  • Select an option

  • Save tuolumne/8660157 to your computer and use it in GitHub Desktop.

Select an option

Save tuolumne/8660157 to your computer and use it in GitHub Desktop.
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.2' )
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
// initialze a new builder and give a default URL
def http = new HTTPBuilder( 'http://www.google.com/search' )
http.request(GET,TEXT) { req ->
uri.path = '/mail/help/tasks/' // overrides any path in the default URL
headers.'User-Agent' = 'Mozilla/5.0'
response.success = { resp, reader ->
assert resp.status == 200
println "My response handler got response: ${resp.statusLine}"
println "Response length: ${resp.headers.'Content-Length'}"
//System.out << reader // print response reader
}
// called only for a 404 (not found) status code:
response.'404' = { resp ->
println 'Not found'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment