Akshat Akshat - 1 year ago 63
Ruby Question

HTTP.post_form in Ruby with custom headers

Im trying to use Nets/HTTP to use

and put in a custom user agent. I've typically used
but it cant do
can it?

I use

resp, data = Net::HTTP.post_form(url, query)

How would I change this to throw custom headers in?

Edit my query is:

query = {'a'=>'b'}


You can try this, for example:

http = Net::HTTP.new('domain.com', 80)
path = '/url'

data = 'form=data&more=values'
headers = {
  'Cookie' => cookie,
  'Content-Type' => 'application/x-www-form-urlencoded'

resp, data = http.post(path, data, headers)