Executing a HTTP GET request easily with HttpClient & a fluent builder

2 votes · 0 comments

This code executes a GET request using the fluent builder for the org.apache.http.client.HttpClient

raw ·
· download
// create a new HttpClient final HttpClient client = new DefaultHttpClient(); // execute a GET-request and get the response as a String final String response = Http.get("http://somesite.com") .use(client) // use this HttpClient (required) .charset("UTF-8") // set the encoding... (optional) .followRedirects(true) // ...follow redirects (optional) .asString(); // execute request // see http://code.google.com/p/httpclient-fluent-builder/

Be the first to comment

Sign in with OpenID