本文介绍了在 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 请求
发布评论