2011-04-12 66 views
0

首先,对于我所知道的可怕的惯用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输出重定向到一个文件,以便您可以看到帖子,如果有帮助的话。

谢谢!

回答

0

我想输入它给了我一些更多的搜索条件,并且我偶然发现了this blog post。尽管我仍然想知道自己做错了什么(我认为我必须使用类似http.start {}的方法来完成此工作),以及我的代码与点击Poster中的按钮的方式不同,将WS-SECURITY标题添加到SOAP请求通过使其成为无状态请求来完全解决问题,而不必在整个流程的整个生命周期中维持状态。

感谢任何花时间阅读本文的人!