在Rails中使用XML发出SOAP请求

Jon*_*ero 6 ruby xml soap ruby-on-rails

我想向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>
Run Code Online (Sandbox Code Playgroud)

Aar*_*tad 6

你可以这样做:

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
Run Code Online (Sandbox Code Playgroud)

此方法将返回XML响应.