Ruby http request with cookie.

require 'net/http'

agencies = [
  "other"
]

cookie = 'copy from browser console'

agencies.each do |agency|
  uri = URI.parse("http://localhost:3000/api/agencies/#{agency}/users")
  req = Net::HTTP::Get.new(uri.request_uri)
  req.add_field('Cookie', cookie)
  http = Net::HTTP.new(uri.host, uri.port)
  res = http.request(req)
  puts "agency=#{agency}, response=#{res.code}"
end
Post tagged with: ruby