how to use curl on ruby on rails? Like this one
curl -d 'params1[name]=name¶ms2[email]' 'http://mydomain.com/file.json'
curl-to-ruby is a tool to instantly convert curl commands to ruby code using net/http in the browser. It does not guarantee high-fidelity conversions, but it's good enough for most API docs that have curl samples.
cURL, which stands for client URL, is a command line tool that developers use to transfer data to and from a server. At the most fundamental, cURL lets you talk to a server by specifying the location (in the form of a URL) and the data you want to send.
Just in case you don't know, it requires 'net/http'
require 'net/http'
uri = URI.parse("http://example.org")
# Shortcut
#response = Net::HTTP.post_form(uri, {"user[name]" => "testusername", "user[email]" => "[email protected]"})
# Full control
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({"user[name]" => "testusername", "user[email]" => "[email protected]"})
response = http.request(request)
render :json => response.body
Hope it'll helps others.. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With