Class | ThinHTTP |
In: |
lib/thin_http.rb
|
Parent: | Object |
ThinHTTP is a light-weight and user friendly HTTP library. This class is useful for sending simple GET requests or uploading files via POST.
By default, it sends URL encoded data (application/x-www-form-urlencoded). MIME multipart encoded data (multipart/form-data) can be sent by utilizing the MIME library or the MultipartFormData class.
th = ThinHTTP.new('rubyforge.org', 80) th.set_header('User-Agent', th.class.to_s) response = th.get('/')
th = ThinHTTP.new('example.com') response = th.post('/submit_form', :param1 => 'val1', :param2 => 'val2')
fd = MIME::MultipartMedia::FormData.new fd.add_entity(MIME::TextMedia.new('Clint'), 'first_name') fd.add_entity(MIME::DiscreteMediaFactory.create('/tmp/pic.jpg'), 'portrait') th = ThinHTTP.new('example.com') response = th.post('/upload_file', fd.body, fd.content_type)
cookies | [RW] | |
host | [R] | |
path | [RW] | |
port | [R] | |
request_headers | [RW] | |
response_headers | [RW] |
Assign initial connection params for host, port, and http_headers. No connection is established until an HTTP method is invoked.
Send params to path as a GET request and return the response body.
params may be a URL encoded String or a Hash.