commonsのHttpClientを試してみた
3.1は古いけど、libに入っていたので3.1の呼び方を確認。
@Grab('commons-httpclient:commons-httpclient:3.1') import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; HttpMethod method = new GetMethod("http://www.google.com/"); try { HttpClient client = new HttpClient(); client.executeMethod(method); return method.getResponseBodyAsString() } finally { method.releaseConnection(); }
Resultにgoogleのトップページのhtmlが入ってた。よしよし。