本文介绍了在Ruby on Rails上的curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在rails上使用curl ruby?像这样一个
how to use curl on ruby on rails? Like this one
curl -d 'params1[name]=name¶ms2[email]' 'http://mydomain.com/file.json'
推荐答案
't知道,它需要'net / http'
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.. :)
这篇关于在Ruby on Rails上的curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!