I just got brain damage again while trying to use NET::HTTP, its so ridiculous complex, why is there no simple alternative ?
(you can use open-uri for get, but post/delete/update ?)
def post(url,data) require 'activesupport' require 'net/http' url = URI.parse(url) http = Net::HTTP.new(url.host, url.port) if url.scheme == 'https' require 'net/https' http.use_ssl = true end resp, data = http.post(url.path, data.to_query) raise "POST FAILED:"+resp.inspect unless resp.is_a? Net::HTTPOK or resp.is_a? Net::HTTPFound return data end
I am willing to make a SimpleHTTP gem if no one comes up with a satisfactory solution 😦
SimpleHTTP::get(url,data) SimpleHTTP::post(url,data) SimpleHTTP::delete(url,data) SimpleHTTP::update(url,data) response = page content, throw exception when response code not 200
rest-client seems to be a good solution, although it does not support sending files.