Skip to content

Instantly share code, notes, and snippets.

@jjarmoc jjarmoc/gist:5367196
Last active Dec 16, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.