Ruby: GET request with curb
Also seen on my weblog: http://blog.monkeyz.eu/2010/09/18/ruby-et-curb-pour-un-meilleur-controle-de-vos-telechargements/
def http_request(url)
curl_handler = Curl::Easy.new()
curl_handler.url = url
curl_handler.timeout = 3
curl_handler.follow_location = true
begin
curl_handler.http_get
rescue Exception => e
return nil
end
resp = Hash[]
resp['code'] = curl_handler.response_code
if curl_handler.response_code == 200
resp['head'] = curl_handler.header_str
resp['body'] = curl_handler.body_str
end
return resp
end