繁体   English   中英

ruby net :: HTTP发出SOAP请求的问题

[英]Problem with ruby net::HTTP issuing a SOAP request

首先,对我所知可怕的惯用Ruby代码感到抱歉。

我试图使用ruby脚本向Oracle CRM OnDemand发出一系列SOAP请求,但遇到了问题。 我可以使用Poster for FireFox很好地发出请求,但是当我尝试用Ruby发出请求时,它会返回以下内容:

内部错误:会话不可用。 中止。

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

我可以获取每个命令的输出,然后通过Poster(登录,查询,注销)将其泵入,这样可以正常工作,但是由于某种原因,将其捆绑在脚本中似乎有些不对。

我想知道是否可能尝试将同一Net :: HTTP用于多个连接是问题? 还是我只是没有正确使用它?

如果有人需要它,我可以尝试找出如何将http输出重定向到文件的方法,以便您可以查看发布信息(如果有帮助的话)。

谢谢!

我想键入它可以为我提供更多搜索条件,而我偶然发现了此博客文章 尽管我仍然想知道自己在做错什么(我想我必须使用类似http.start {}的东西才能使它工作),以及我的代码与单击Poster中的按钮有何不同,并添加WS-SECURITY标头SOAP请求通过使其成为无状态请求来完全解决了问题,而不必在整个过程的生命周期内维护状态。

感谢所有花时间阅读本文的人!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM