Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created November 20, 2009 15:27
Show Gist options
  • Save ohadlevy/239561 to your computer and use it in GitHub Desktop.
Save ohadlevy/239561 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require "net/http"
require "uri"
require "cgi"
url_new = URI.parse('http://localhost/hosts/new:3000')
url_create = URI.parse('http://localhost/hosts/create:3000')
resp, data = Net::HTTP.new(url_new.host, url_new.port).get("/hosts/new", nil)
cookie = resp.response['set-cookie']
token=data.match(/<input name=\"authenticity_token\" type=\"hidden\" value=\"(.*)\"/)[1]
# now post the data
#
puts token
data = "authenticity_token=#{CGI.escape token}&record[name]=servername.domain&record[environment[id]=1]"
headers = {
'Cookie' => cookie,
'Content-Type' => 'application/x-www-form-urlencoded' }
resp, data = Net::HTTP.new(url_create.host, url_create.port).post("/hosts/create", data, headers)
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
#resp.each {|key, val| puts key + ' = ' + val}
#puts data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment