Skip to content

Instantly share code, notes, and snippets.

@jameskbride
Created September 29, 2012 14:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameskbride/3804157 to your computer and use it in GitHub Desktop.
Save jameskbride/3804157 to your computer and use it in GitHub Desktop.
HTTPBuilder Binary Response Example
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