HttpClient Fluent API
概述
使用
Get請求
Request.Get(url).execute().returnContent().asString()
Post請求
Request.Post(url).bodyString(paramStr, ContentType.DEFAULT_TEXT)
.execute().returnContent().asString()
// ContentType = application/x-www-form-urlencoded
Request.Post(url).bodyForm(paramForm).execute().saveContent(new File("foo.txt"))
緩存、複用認證信息
Executor executor = Executor.newInstance().auth(new HttpHost("hostname", port), "username", "password")
executor.execute(Request.Post(url).bodyForm(form)).returnContent().asString()
ResponseHandler
Request.Post(url).bodyString(paramStr, ContentType.DEFAULT_TEXT)
.execute().handleResponse(new ResponseHandler<>() {
});