Created
January 28, 2014 00:27
-
-
Save tuolumne/8660157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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