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
##
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
def send_request
require 'net/http'
require 'uri'
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",
"b" => "456"
}.to_json
}
request = Net::HTTP::Post.new(initheader = {'Content-Type' =>'application/json'})
request.body = @body
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(body)
response = Net::HTTP.start(uri.host, uri.port) do |http|
http.request(request)
end
response = http.request(request)
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}"
end

View File

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