Last active
December 16, 2015 03:08
-
-
Save jjarmoc/5367196 to your computer and use it in GitHub Desktop.
Start of ruby HTTP automation...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs;
POST to http://www.example.com/posthere yielded 302
GET to http://www.example.com/gethere yielded 302