Hi,
The following is a modified version of the http client found in the
o'reilly ruby cookbook.
Does any one know how I can add custom cookies to this?
class HTTP
# Makes an HTTP reuqest and returns the HTTPRespnse object.
# Args: :proxy_host, :proxy_port, :action (:get, :post, etc.),
# :data (for :post action), :max_redirects.
def HTTP.fetch(uri, args={}.freeze, &before_fetching)
# Process the arguments with default values
uri = URI.parse(URI.encode(uri)) unless uri.is_a? URI
proxy_host = args[:proxy_host]
proxy_port = args[:proxy_port] || 80
action = args[:action] || :get
data = args[:data]
max_redirects = args[:max_redirects] || 10
cookies = args[:cookies] || ''
# Set http headers
headers = {'Cookie' => cookies}
# Use proxy class to create the request object
proxy_class = Proxy(proxy_host, proxy_port)
request = proxy_class.new(uri.host, uri.port)
# Organise the query
if action == 'get'
query = uri.path.to_s + "?" + uri.query.to_s
else
query = uri.path.to_s + '/'
end
response = request.send(action, query, data)
return response
end
Thank you in advance!
···
--
Posted via http://www.ruby-forum.com/.