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

Post a Comment

Popular posts from this blog

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

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

SELECT COUNTRY WITH STATE AND IT'S CITIES RAILS

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

Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension.

HOW TO CALL RAILS API FROM SIMPLE HTML PAGE.

CREATE API FOR USER SIGN UP, LOGIN AND CREATE PUBLISHER WITH CURRENT USER