在Rails中使用XML发出SOAP请求
我想向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 string string int string unsignedByte int string
你可以这样做:
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响应。