Allow sending request and getting response

This commit is contained in:
Bernie Chiu 2013-09-10 16:31:35 +08:00 committed by chris
parent bf5416095e
commit da40c2b669
2 changed files with 14 additions and 13 deletions

View File

@ -34,28 +34,29 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
## ##
send_request send_request
## ##
redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success') redirect_to panel_ask_back_end_ask_questions_path # , notice: t('ask.reply_success')
end end
def send_request def send_request
require 'net/http' require 'net/http'
require 'uri' require 'uri'
require 'json' require 'json'
uri = URI.parse("http://localhost/ask/back_end/ask_requests/auth_request:3000")
@body = { uri = URI.parse("http://localhost:4000/panel/ask/back_end/ask_requests/auth_request")
body = {
"a" => "123", "a" => "123",
"b" => "456" "b" => "456"
}.to_json }
request = Net::HTTP::Post.new(initheader = {'Content-Type' =>'application/json'}) http = Net::HTTP.new(uri.host, uri.port)
request.body = @body request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(body)
response = Net::HTTP.start(uri.host, uri.port) do |http| response = http.request(request)
http.request(request)
end
puts "Response #{response.code} #{response.message}: #{response.body}" puts "Response #{response.code} #{response.message}: #{response.body}"
# flash[:notice]=response.message flash[:notice] = response.body
# flash[:notice] = "Response #{response.code} #{response.message}: #{response.body}" # flash[:notice] = "Response #{response.code} #{response.message}: #{response.body}"
end end

View File

@ -4,7 +4,7 @@ class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController
include OrbitControllerLib::DivisionForDisable include OrbitControllerLib::DivisionForDisable
def auth_request def auth_request
params.merge!({'c' => '789'})
render :json => "#{params}"
end end
end end