Skip to content

Instantly share code, notes, and snippets.

@jorwan
Last active August 29, 2015 14:03
Show Gist options
  • Save jorwan/70d74f160852f711c4e6 to your computer and use it in GitHub Desktop.
Save jorwan/70d74f160852f711c4e6 to your computer and use it in GitHub Desktop.
Ruby
require 'net/http'
require 'json'
#HACER UN GET REQUEST
def getRequest(url)
url = URI.parse(url)
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
res.body
end
#HACER UN POST REQUEST
def postRequest(url, params={})
uri = URI(url);
https = Net::HTTP.new(uri.host, uri.port)
headers = {
"Accept" => "application/json",
"Content-type" => "application/json"
}
https.post(uri.path, JSON.generate(params), headers).body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment