简体   繁体   中英

Ruby : How to make a HttpRequest

I'm still new in ruby, please help. I'm trying to make a http request in my standalone ruby script.

#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
...
class someClass
...
def get_ruby_doc
  request = HttpRequest.new(:get, 'http://www.ruby-doc.org/')
  response = request.perform!
  puts response.succeeded?
  puts "yeah"
end
...

when I run the script, I get this error:

Uncaught exception: uninitialized constant someClass::HttpRequest

Can you please let me know what did I miss? Thanks.

I also try to do the same in rails console, same error.

You could try using rest-client

gem install rest-client

http://rubydoc.info/gems/rest-client/1.6.7/frames

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM