Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created April 7, 2010 01:55
Show Gist options
  • Save makevoid/358384 to your computer and use it in GitHub Desktop.
Save makevoid/358384 to your computer and use it in GitHub Desktop.
Posting with Net::HTTP
url = URI.parse('http://www.example.com/todo.cgi')
req = Net::HTTP::Post.new(url.path)
req.basic_auth 'jack', 'pass'
req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment