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
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
UPDATE:
rest-client seems to be a good solution, although it does not support sending files.

2 comments
Comments feed for this article
February 2, 2009 at 0:56
Sam
what about open-uri?
February 2, 2009 at 7:27
pragmatig
“(you can use open-uri for get, but post/delete/update ?)”
as far as i know open-uri only works for get requests, not post/put/delete