3 ms·
With all due respect, Net::HTTP is clunky. I'm typing the following from memory, too: require 'open-uri' response = open("http://blog.segment7.net/").r
by aaronbrethorst 16y ago
With all due respect, Net::HTTP is clunky. I'm typing the following from memory, too:
require 'open-uri'
response = open("http://blog.segment7.net/").read
- derefr 16y agoIf you're doing more than one of those in a single document, having a persistent connection object and sending it request messages wins. (Though open-uri could actually do this, if it cached the connection objects by host:port.)
- catch23 16y agothat's great if all you're trying to do is HTTP GET. standard libs are supposed to make all use cases fairly easy. making an http post isn't too bad: Net::HTTP.new(host, port).start do |http| post = Net::HTTP::Post.new(url) post.set_form_data('blah' => '123') http.request(post) end
- petercooper 16y agoThat's "not too bad" if you're coming from Java. Thankfully most other Ruby libraries have significantly less verbose APIs than this.
- aaronbrethorst 16y agoPersonally, I'm a big fan of open-uri for super-simple requests and HTTParty for anything more complex.
- carbon8 16y agoThere's a much simpler way to do POSTs with Net::HTTP: response = Net::HTTP.post_form(URI.parse("http://example.com"), {:param => "val"})