在 Rails 中使用 XML 发出 SOAP 请求

编程入门 行业动态 更新时间:2024-10-27 03:27:52
本文介绍了在 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 Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:xsd="www.w3/2001/XMLSchema" xmlns:soap12="www.w3/2003/05/soap-envelope"> <soap12:Body> <Tick xmlns="demo/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 = "demo.demo" 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 请求

本文发布于:2023-10-09 18:51:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails   XML   SOAP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!