Skip to content

Instantly share code, notes, and snippets.

@jogam5
Created June 8, 2014 20:08
Show Gist options
  • Save jogam5/4f73025a65b6f6fad0b3 to your computer and use it in GitHub Desktop.
Save jogam5/4f73025a65b6f6fad0b3 to your computer and use it in GitHub Desktop.
http-request
require "net/http"
require "uri"
uri = URI.parse("http://example.com/search")
# Shortcut
response = Net::HTTP.post_form(uri, {"q" => "My query", "per_page" => "50"})
# Full control
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({"q" => "My query", "per_page" => "50"})
# Tweak headers, removing this will default to application/x-www-form-urlencoded
request["Content-Type"] = "application/json"
response = http.request(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment