All pastes #46728 Raw Edit

Anonymous

public ruby v1 · immutable
#46728 ·published 2006-03-23 19:01 UTC
rendered paste body
require 'net/http'class String  # Returns the contents of the string, assuming it is a url. Could be dangerous.  def get(body = nil)    resp = perform(:get, body)    resp.body  end    # Attempts to parse <code>self</code> as a URL and then performs an HTTP POST on it, with  # the optional parameter as the body of the post.  Returns the result of the post.  def post(body = nil)    resp = perform(:post, body)    resp.code_type == Net::HTTPOK  end    private  def perform(get_or_post, body)    url = URI.parse self    http = Net::HTTP.new(url.host, url.port)    return http.send(get_or_post, url.path, body)  end  end