Equivalent of cURL for Ruby?

前端 未结 12 2650
不知归路
不知归路 2020-11-29 00:33

Is there a cURL library for Ruby?

12条回答
  •  执笔经年
    2020-11-29 01:24

    the eat gem is a "replacement" for OpenURI:

    # first do gem install eat
    require 'eat'
    eat('http://yahoo.com')                 #=> String
    eat('/home/seamus/foo.txt')             #=> String
    eat('file:///home/seamus/foo.txt')      #=> String
    

    It uses HTTPClient under the hood. It also has some options:

    eat('http://yahoo.com', :timeout => 10)                   # timeout after 10 seconds
    eat('http://yahoo.com', :limit => 1024)                   # only read the first 1024 chars
    eat('https://yahoo.com', :openssl_verify_mode => 'none')  # don't bother verifying SSL certificate
    

提交回复
热议问题