I’ve seen the topic here a bunch of times but none of the responses solved my problem.
I’m parsing a IOT device’s XML file. Here’s what I’ve got for code:
def params = [
uri: "http://${settings.username}:${settings.password}@${settings.host}:${settings.port}/sx.xml?${settings.deviceid}=1900",
contentType: 'text/xml'
]
try {
httpGet(params) { resp ->
// iterate all the headers
// each header has a name and a value
resp.headers.each {
log.debug "${it.name} : ${it.value}"
}
// get an array of all headers with the specified key
def theHeaders = resp.getHeaders("Content-Length")
// get the contentType of the response
log.debug "response contentType: ${resp.contentType}"
// get the status code of the response
log.debug "response status code: ${resp.status}"
// get the data from the response body
log.debug "response data: ${resp.data}"
log.debug resp.data.Xs
log.debug resp.data.Xs.X
log.debug resp.data.Xs.@D
resp.data.children().each { log.debug it.name }
log.debug resp.data.inspect
}
} catch (e) {
log.error "something went wrong: $e"
}
The outputs I’m getting:
debug null
debug
debug
debug
debug
debug
debug response data:
debug response status code: 200
debug response contentType: text/xml
debug Access-Control-Allow-Origin : *
debug Cache-Control : no-cache
debug Content-Type : text/xml
debug Connection : close
Here’s what the XML file looks like:
<Xs>
<X D="248D8F250070"/>
</Xs>