"あの"Javaで、こんなにも短くHTTPリクエストを書けるなんて!

apache projectの fluent APIを使うと、
実質数十行にも及ぶJavaのHTTPリクエストを大幅に簡略化できる。
(公式)
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fluent.html

  • GETリクエストを送信し、結果を文字列として返す

Request.Get("http://somehost/")
.connectTimeout(1000)
.socketTimeout(1000)
.execute().returnContent().asString();

  • POSTリクエストを送信し、結果をファイルに保存する

Request.Post("http://somehost/some-form")
.addHeader("X-Custom-header", "stuff")
.viaProxy(new HttpHost("myproxy", 8080))
.bodyForm(Form.form().add("username", "vip").add("password", "secret").build())
.execute().saveContent(new File("result.dump"));

プロキシもその認証も楽勝
 
直感的に理解できるし、ちょっと感動的な簡単さだ。。。。。