@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.1.3') import org.apache.http.client.entity.* import org.apache.http.client.methods.* import org.apache.http.impl.client.* import org.apache.http.message.* import org.apache.http.protocol.* import groovy.json.* def _apikey = "yourkey" def base = "https://api.mongohq.com/databases" def db = "mydb" def col = "employee" httpclient = new DefaultHttpClient() method = new HttpPost("${base}/${db}/collections?_apikey=${_apikey}") values = [ new BasicNameValuePair('name', col) ] method.setEntity(new UrlEncodedFormEntity(values, HTTP.UTF_8)) response = httpclient.execute(method) println response.getStatusLine().getStatusCode() println response.getEntity().getContent().text
動作環境
groovy 1.8.6
関連情報
groovyとMongoDBのまとめ
0 件のコメント:
コメントを投稿