【发布时间】:2014-11-03 14:18:03
【问题描述】:
我有两个 Rails 应用程序。 App #1 从一个控制器动作向 App #2 中的另一个控制器动作发送一个 post 请求。我希望能够在 App #1 中读取对该 POST 的响应。
App #1 控制器:
require 'net/http'
# get the url that we need to post to
url = URI.parse('http://app2.com/sessions/login_request')
# build the params string
post_args1 = {
'username' => 'my@test.com'
}
# send the request
resp, data = Net::HTTP.post_form(url, post_args1)
#HOW do I read :token and :tokenMnemonic here??
应用 #2 控制器:
def login_request
# do some logic here
render :json => {
:result => "OK",
:token => random_token,
:tokenMnemonic => tokenMnemonic
}
end
问题是我如何从 App #1 的控制器收到的 POST 响应中读取 :token 和 :tokenMnemonic。
【问题讨论】:
标签: ruby-on-rails http post