サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.6') import org.apache.http.client.methods.* import org.apache.http.impl.client.* import org.apache.http.message.* import org.apache.http.auth.* import org.apache.http.entity.* import groovy.json.* def host = "192.168.1.212" // replace this def port = 8080 def serviceKey = "your-service-key" def httpclient = new DefaultHttpClient() httpclient.withCloseable { def method = new HttpGet( "http://${host}:${port}/api/containers" ) method.setHeader("X-Service-Key", serviceKey) def response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def rjson = new JsonSlurper().parseText(response.getEntity().getContent().text) rjson.each { print "id:${it.id}, container name:${it.name}, " println "image name:${it.image.name}, running:${it.state}" } }
関連情報
0 件のコメント:
コメントを投稿