【问题标题】:Making a SOAP request by using XML in Rails在 Rails 中使用 XML 发出 SOAP 请求
【发布时间】:2009-07-26 15:09:08
【问题描述】:

我想向 SOAP Web 服务发出请求,但我不想安装任何 gem。 有没有办法只使用纯 XML 发出请求?

我认为这很简单,但我可能遗漏了一些东西,因为所有实现/教程都使用了 gem。

我认为SOAP响应,也可以作为XML响应来处理吧?

请求是这样的:

POST /services/tickets/issuer.asmx HTTP/1.1
Host: demo.demo.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Tick xmlns="http://demo.com/test/test">
      <Request>
        <Username>string</Username>
        <Password>string</Password>
        <AcquirerId>int</AcquirerId>
        <RequestType>string</RequestType>
        <ExpirePreauth>unsignedByte</ExpirePreauth>
        <BitPerSec>int</BitPerSec>
        <Office>string</Office>
      </Request>
    </Tick>
  </soap12:Body>
</soap12:Envelope>

【问题讨论】:

    标签: ruby-on-rails xml ruby soap


    【解决方案1】:

    你可以这样做:

    def post_xml(path, xml)
      host = "http://demo.demo.com"
      http = Net::HTTP.new(host)
      resp = http.post(path, xml, { 'Content-Type' => 'application/soap+xml; charset=utf-8' })
      return resp.body
    end
    

    此方法将返回 XML 响应。

    【讨论】:

    • 使用 Ruby 1.9.2 和 Rails 3.2.12 - 我必须从主机名中删除“http://”。此外,使用 SOAP 1.1 并且必须将 'Content-Type' 设置为 text/xml 谢谢!
    • 我正在尝试解决类似的问题,并设置了类似的解决方案。但是,我尝试发布到的服务器需要用户身份验证。您对设置凭据有什么建议吗?
    • 这是什么path 变量?
    猜你喜欢
    • 2011-11-13
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多