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/
  1. def http_request(url)
  2. curl_handler = Curl::Easy.new()
  3. curl_handler.url = url
  4.  
  5. curl_handler.timeout = 3
  6. curl_handler.follow_location = true
  7.  
  8. begin
  9. curl_handler.http_get
  10. rescue Exception => e
  11. return nil
  12. end
  13.  
  14. resp = Hash[]
  15. resp['code'] = curl_handler.response_code
  16.  
  17. if curl_handler.response_code == 200
  18. resp['head'] = curl_handler.header_str
  19. resp['body'] = curl_handler.body_str
  20. end
  21.  
  22. return resp
  23. end
Permalink  Download