gpt4 book ai didi

ruby-on-rails - 在 Rails 中使用 XML 发出 SOAP 请求

转载 作者:数据小太阳 更新时间:2023-10-29 01:51:15 29 4
gpt4 key购买 nike

我想向 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>

最佳答案

你可以这样做:

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-on-rails - 在 Rails 中使用 XML 发出 SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1184802/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com