首先,对于我所知道的可怕的惯用Ruby代码感到抱歉。ruby net问题::发出SOAP请求的HTTP
我想使用ruby脚本向Oracle CRM OnDemand发出一系列SOAP请求,并且遇到问题。我可以就好使用Poster对于Firefox发出请求,但是当我试图用Ruby发给他们,这回踢如下:
Internal Error: Session is not available. Aborting.
Oracle托管型CRM OnDemand的需要授权会话cookie。下面是我使用的代码:
httpOracle = Net::HTTP.new(ORACLE_BASE_URL, ORACLE_PORT)
httpOracle.use_ssl = true
httpOracle.verify_mode = OpenSSL::SSL::VERIFY_NONE
httpOracle.set_debug_output $stderr
begin
# CONNECT TO ORACLE AND RETRIEVE A SESSION ID
pathOracle = buildOracleLoginPath()
headOracle = { "username" => ORACLE_USERNAME,
"password" => ORACLE_PASSWORD }
respOracle = httpOracle.request_head(pathOracle, headOracle)
authOracle = respOracle['set-cookie']
.gsub(/ /, '')
.split(';')
.find_all { |item| item.match(/^JSESSIONID=/) }[0].to_s
# RETRIEVE ALL ORACLE LEADS
pathOracle = buildOraclePath(authOracle)
headOracle = { "soapaction" => buildOracleSOAPAction("Lead", "QueryPage"),
"Content-Type" => "text/xml" }
rqstOracle = loadPostData 'soap.xml' # Loads file with SOAP payload as a string
respOracle = httpOracle.request_post(pathOracle, rqstOracle, headOracle)
puts respOracle # for testing
rescue
puts "Error #{$!}"
ensure
# CLOSE THE CONNECTION TO ORACLE
pathOracle = buildOracleLogoffPath()
headOracle = { authOracle.split('=')[0] => authOracle.split('=')[1] }
respOracle = httpOracle.request_head(pathOracle, headOracle)
end
我可以把每一个这些命令的输出,并通过海报泵它(登录,查询,注销),它会工作得很好,但由于某种原因,它看起来像是在脚本中捆绑在一起的东西是错误的。
我想知道如果也许尝试使用相同的Net :: HTTP进行多个连接是问题吗?或者,也许我只是不正确地使用它?
如果有人需要它,我可以尝试弄清楚如何将http输出重定向到一个文件,以便您可以看到帖子,如果有帮助的话。
谢谢!