Created
September 29, 2012 14:26
-
-
Save jameskbride/3804157 to your computer and use it in GitHub Desktop.
HTTPBuilder Binary Response Example
This file contains 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
def getBinaryStream(params) { | |
def data | |
def http = new HTTPBuilder("http://google.com/baseURI") | |
http.request(Method.GET, ContentType.BINARY) {req -> | |
//uri.path = "/a/relative/path/here" | |
uri.port = "8080" | |
uri.query = [userName: "user", password:"password"] | |
headers.'User-Agent' = 'Mozilla/5.0' | |
headers.'Accept' = 'application/octet-stream' | |
response.'200' = {resp, binary -> | |
log.info(resp.statusLine) | |
data = binary.bytes //binary in this case is an instance of InputStream | |
} | |
response.failure = {resp -> | |
log.error("Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}") | |
log.error(uri.query) | |
log.error(uri.toString()) | |
throw new Exception("There was an error retrieving the file") | |
} | |
} | |
data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment