Skip to content

Instantly share code, notes, and snippets.

@psahni
Created March 19, 2015 05:56
Show Gist options
  • Save psahni/3771fe5b777c8d1450cb to your computer and use it in GitHub Desktop.
Save psahni/3771fe5b777c8d1450cb to your computer and use it in GitHub Desktop.
ruby_http_example
require 'uri'
require 'net/http'
url = URI("http://mockbin.com/request?foo=bar&foo=baz")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["cookie"] = 'foo=bar; bar=baz'
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request.body = "{\"foo\": \"bar\"}"
response = http.request(request)
puts response.read_body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment