サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.5') import org.apache.http.client.methods.* import org.apache.http.impl.client.* import org.apache.http.auth.* import groovy.json.* def host = "192.168.1.219" def port = 15672 def user = "guest" def pass = "guest" def httpclient = new DefaultHttpClient() httpclient.getCredentialsProvider().setCredentials( new AuthScope(host, port), new UsernamePasswordCredentials(user, pass) ) def method = new HttpGet("http://${host}:${port}/api/users") response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def json = new JsonSlurper().parseText(response.getEntity().getContent().text) println json println "----" for(ruser in json){ println "[${ruser.name}]:tags=${ruser.tags}" }動作環境
groovy 2.3.6, JDK7 update 65, RabbitMQ 3.3.5
0 件のコメント:
コメントを投稿