Skip to content

Instantly share code, notes, and snippets.

@aliang
Created March 9, 2010 17:25
Show Gist options
  • Select an option

  • Save aliang/326846 to your computer and use it in GitHub Desktop.

Select an option

Save aliang/326846 to your computer and use it in GitHub Desktop.

Revisions

  1. aliang revised this gist Mar 9, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions custom_headers.rb
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@

    req = Net::HTTP::Get.new(url.path)
    req.add_field("X-Forwarded-For", "0.0.0.0")
    # For content type, you could also use content_type=(type, params={})
    # req.set_form_data({'query' => 'search me'})
    # req['X-Forwarded-For'] = "0.0.0.0"

  2. aliang renamed this gist Mar 9, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. aliang created this gist Mar 9, 2010.
    17 changes: 17 additions & 0 deletions set custom headers with net/http
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # this was surprisingly difficult to find, the documentation and API is poor

    require "net/http"
    require "uri"

    url = URI.parse("http://www.whatismyip.com/automation/n09230945.asp")

    req = Net::HTTP::Get.new(url.path)
    req.add_field("X-Forwarded-For", "0.0.0.0")
    # req.set_form_data({'query' => 'search me'})
    # req['X-Forwarded-For'] = "0.0.0.0"

    res = Net::HTTP.new(url.host, url.port).start do |http|
    http.request(req)
    end

    puts res.body