Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
setting custom headers with ruby net/http
# this was surprisingly difficult to find, the documentation and API is poor
require "net/http"
require "uri"
url = URI.parse("")
req =
req.add_field("X-Forwarded-For", "")
# For content type, you could also use content_type=(type, params={})
# req.set_form_data({'query' => 'search me'})
# req['X-Forwarded-For'] = ""
res =, url.port).start do |http|
puts res.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment