我知道有很多关于如何使用Ruby来发出SOAP请求的文章(通常引用了gem ),但我对它们没有太多的理解(我对编程完全是个新手)。我能够成功地访问API并使用soaupUI执行get请求,而我只是在寻找其他方法来使用Ruby来完成这些请求。以下是我的意见:
我将识别信息替换为“.”我是否可以简单地使用这些输入来启动soap请求?
谢谢!
编辑:好的,考虑到下面的注释,下面是我试图访问的一个实践API。端点是http://www.thomas-bayer.com:80/axis2/services/BLZService,我从soupUI复制了soap,在那里我能够成功地执行请求。
require 'net/http'
require 'net/https'
http = Net::HTTP.new('thomas-bayer.com', 80)
http.use_ssl = false
path = 'axis2/services/BLZService'
data = <<-EOF
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blz="http://thomas-bayer.com/blz/">
<soapenv:Header/>
<soapenv:Body>
<blz:blz>70070010</blz:blz>
</blz:getBank>
</soapenv:Body>
</soapenv:Envelope>
EOF
headers = {
'Referer' => 'http://www.appfusion.net',
'Content-Type' => 'text/xml',
'Host' => 'thomas-bayer.com'
}
resp, data = http.post(path, data, headers)
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each { |key, val| puts key + ' = ' + val }
puts data
当我运行它时,会返回许多不同的错误。解决这个问题的任何帮助都是非常感谢的;下面是wsdl,如果这有帮助的话:http://www.thomas-bayer.com/axis2/services/BLZService?wsdl(如果是那样的话)
发布于 2013-04-23 17:10:49
我想出了一种非常简单的方法,可以使用savon中的soap.xml类(version 1)来实现这一点:
client = Savon.client("www.mywsdl.wsdl")
response = client.request :get_my_request do
soap.xml ='my xml code'
end
https://stackoverflow.com/questions/16157640
复制相似问题