Skip to content

Instantly share code, notes, and snippets.

@hryk
Created August 15, 2010 11:36
Show Gist options
  • Select an option

  • Save hryk/525395 to your computer and use it in GitHub Desktop.

Select an option

Save hryk/525395 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'java'
require File.dirname(__FILE__) + "/../jars/commons-logging-1.1.1.jar"
require File.dirname(__FILE__) + "/../jars/httpcore-4.0.1.jar"
require File.dirname(__FILE__) + "/../jars/httpclient-4.0.1.jar"
import "org.apache.http.client.ResponseHandler"
import "org.apache.http.client.HttpClient"
import "org.apache.http.client.methods.HttpGet"
import "org.apache.http.impl.client.BasicResponseHandler"
import "org.apache.http.impl.client.DefaultHttpClient"
=begin
This example demonstrates the use of the {@link ResponseHandler} to simplify
the process of processing the HTTP response and releasing associated resources.
=end
client = DefaultHttpClient.new
httpget = HttpGet.new("http://www.google.com/")
puts "executing request " +httpget.getURI().toString()
response_handler = BasicResponseHandler.new()
response_body = client.execute(httpget, response_handler)
puts response_body
=begin
When HttpClient instance is no longer needed,
shut down the connection manager to ensure
immediate deallocation of all system resources
=end
client.getConnectionManager().shutdown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment