|
Project Information
|
A fluent builder on top of Apache's HttpClient to simplify its usage for common cases. This implementation is and will remain compatible with the Android API. Usage examplesSimple GET-requestfinal String site = Http.get("http://somesite.com").use(client).asString();Extended GET-requestThe following example is using a RequestCustomizer (let's you modify the request just before it is being executed) and a custom (weird) ResponseHandler: final String ok =
Http.get("http://somesite.com")
.use(client)
.header("User-Agent", "HttpClient Wrapper")
.charset("UTF-8")
.followRedirects(true)
.customize(new RequestCustomizer() {
@Override
public void customize(final HttpUriRequest request) {
HttpProtocolParams.useExpectContinue(request.getParams());
}
})
.as(new ResponseHandler<String>() {
@Override
public String handleResponse(final HttpResponse response) throws IOException {
final int statusCode = response.getStatusLine().getStatusCode();
return statusCode == HttpStatus.SC_OK ? "YES" : "NO";
}
});Simple POST-request...sending some data to the site: final HttpResponse response =
Http.post("http://somesite.com")
.use(client)
.data("search_name", "Mike")
.data("search_gender", "m")
.asResponse();Execution methodsThere are several methods to execute the request created with this builder. Here a brief overview about them:
See more in the code :-) |