這裏是我的問題:回報率登錄到頁面,POST數據到遠程URL
我需要從RoR的服務器的數據發佈到遠程PHP服務器,到特定的URL,但在此之前,我需要進行身份驗證..任何幫助非常感謝..
我迄今所做..
#sample data
postparams ={'id'=>1, 'name'=>'Test', 'phone'=>'123123123'}
#url - is in form http://domain.com/some/somemore
#user - contains username
#pass - contains password
require "uri"
require "net/http"
uri = URI(url)
req = Net::HTTP::Post.new(uri.path)
req.set_form_data(postparams)
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
case res
when Net::HTTPSuccess, Net::HTTPRedirection
#all ok
else
res.value
end
很顯然,我得到403 ..因爲我沒有授權?我如何授權?
我也想我的運氣機械化寶石(以下 - 使用相同的「樣本」數據\乏)
#when not logged in it renders login form
login_form = agent.get(url).forms.first
login_form.username = user
login_form.password = pass
# submit login form
agent.submit(login_form, login_form.buttons.first)
#not sure how to submit to url..
#note that accessing url will not render the from
#(I can't access it as I did with login form) - I simply need to post postparams
#to this url... and get the response code..