Last active
August 29, 2015 14:03
-
-
Save jorwan/70d74f160852f711c4e6 to your computer and use it in GitHub Desktop.
Ruby
This file contains 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 '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