在 Rails 中使用 XML 发出 SOAP 请求 [英] Making a SOAP request by using XML in Rails

查看:31
本文介绍了在 Rails 中使用 XML 发出 SOAP 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to make a request to a SOAP Web Service but I don't want to install any gems. Is there any way to just make the request using plain XML?

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

I think it's trivial but there might be something I've missed, because all implementations/tutorials were using a gem.

我认为 SOAP 响应也可以作为 XML 响应处理,对吗?

I think that the SOAP response, can be handled also as a XML response right?

请求是这样的:

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>

推荐答案

你可以这样做:

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 响应.

The XML response would be returned by this method.

这篇关于在 Rails 中使用 XML 发出 SOAP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆