Skip to content

Instantly share code, notes, and snippets.

@jjarmoc
Last active December 16, 2015 03:08
Show Gist options
  • Save jjarmoc/5367196 to your computer and use it in GitHub Desktop.
Save jjarmoc/5367196 to your computer and use it in GitHub Desktop.
Start of ruby HTTP automation...
require 'httpclient'
cmds = [
{ :method => "POST", :uri => "http://www.example.com/posthere", :body=>{ 'userid' => 'user', 'pw'=>'password'}, :response=>nil},
{ :method => "GET", :uri =>"http://www.example.com/gethere", :body=>{}, :response=>nil}
]
client = HTTPClient.new
client.set_cookie_store('cookie.dat')
cmds.each do |cmd|
#p url
response = case cmd[:method]
when "GET" then client.get(cmd[:uri])
when "POST" then client.post(cmd[:uri], cmd[:body])
else "UNDEFINED"
end
cmd[:response]=response
end
cmds.each do |cmd|
p "#{cmd[:method]} to #{cmd[:uri]} yielded #{cmd[:response].status}"
end
@jjarmoc
Copy link
Author

jjarmoc commented Apr 11, 2013

Outputs;

POST to http://www.example.com/posthere yielded 302
GET to http://www.example.com/gethere yielded 302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment