Created
June 8, 2014 20:08
-
-
Save jogam5/4f73025a65b6f6fad0b3 to your computer and use it in GitHub Desktop.
http-request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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