CURL COMMAND ON RUBY ON RAILS

HOW TO USE CURL ON RUBY ON RAILS? LIKE THIS ONE

curl -d 'params1[name]=name&params2[email]' 'http://mydomain.com/file.json'

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]" => "testemail@yahoo.com"})   
# 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]" => "testemail@yahoo.com"}) 
response = http.request(request) 
render :json => response.body

Hope it'll helps others.. :)

We can also follow the link below :-

https://stackoverflow.com/questions/15804425/curl-on-ruby-on-rails

Comments

Popular posts from this blog

psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

CARRIERWAVE - UPLOAD ANY MEDIA (AUDIO , VIDEO AND IMAGE ) FILE IN RAILS

SELECT COUNTRY WITH STATE AND IT'S CITIES RAILS

RAILS: UPLOADING PHOTOS VIA AMAZON S3 AND PAPERCLIP (UPLOADING FILES TO S3 IN RUBY WITH PAPERCLIP)

SEARCHING USING AJAX IN RAILS

UPLOAD ANY MEDIA FILE IN RAILS USING PAPERCLIP

UNINITIALIZED CONSTANT PAPERCLIP::STORAGE::S3::AWS

CHECK PASSENGER RUBY PATH