我想向soapweb服务发出请求,但我不想安装任何gems。
我认为这很简单,但我可能遗漏了一些东西,因为所有的实现/教程都使用了gem。
请求如下:
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响应。