Ruby:Savon SOAP请求接收400和415个错误

Ruby:Savon SOAP请求接收400和415个错误,ruby,soap,savon,Ruby,Soap,Savon,我正在尝试使用ruby库Savon发出SOAP请求 我正在使用以下代码: require "savon" Savon.configure do |config| config.soap_version = 2 # use SOAP 1.2 config.raise_errors = false end wsdl_logon = Savon::Client.new do wsdl.document = "https://api.affili.net/V2.0/Logo

我正在尝试使用ruby库Savon发出SOAP请求

我正在使用以下代码:

require "savon"

Savon.configure do |config|
    config.soap_version = 2  # use SOAP 1.2
    config.raise_errors = false
end

wsdl_logon = Savon::Client.new do
    wsdl.document = "https://api.affili.net/V2.0/Logon.svc?wsdl"
end

username = 'XXX'
password = 'YYY'

wsdl_logon.http.headers["Content-Type"] = "text/xml; charset=utf-8"

response = wsdl_logon.request "Logon" do
  soap.body = {'Username' => username, 'Password' => password, 'WebServiceType' => 'Product'}
end

if response.http_error?
    puts "Http Error!"
    puts y response.http_error
else
    puts "No Http Error!"
end
但我一直收到400条错误消息(“错误请求”)。或者,如果我删除以下行

wsdl_logon.http.headers["Content-Type"] = "text/xml; charset=utf-8"
我收到415条错误消息(“不支持的媒体类型”)

到目前为止,我一直在使用PHP发出这些请求,下面的代码总是毫无问题地工作:

$soap_logon = new SoapClient('https://api.affili.net/V2.0/Logon.svc?wsdl');
$token = $soap_logon->Logon(array(
    'Username'      => 'XXX',
    'Password'      => 'YYY',
    'WebServiceType'    => 'Product'
));
有人能给我指出正确的方向吗?可能的错误源是什么?我现在完全迷路了

谢谢你的帮助


我按照Tom De Leu的建议做了,并尝试尽可能消除所生成的SOAP请求中的差异。但我仍然收到400个错误。任何关于可能原因的提示都将不胜感激

这是PHP生成的(工作)请求(为清晰起见,添加了XML中的换行符):

POST/V2.0/Logon.svc HTTP/1.1
主机:api.affili.net
连接:保持活力
用户代理:PHP-SOAP/5.2.0-8+16
内容类型:text/xml;字符集=utf-8
SOAPAction:“http://affilinet.framework.webservices/Svc/ServiceContract1/Logon"
内容长度:456
xxx
yyy
产品
这是Ruby生成的(不工作)请求(同样,为了清晰起见添加了xml换行符)

SOAP请求:https://api.affili.net/V2.0/Logon.svc
内容类型:text/xml;字符集=utf-8,SOAPAction:http://affilinet.framework.webservices/Svc/ServiceContract1/Logon,内容长度:605
XXX
YYY
产品
HTTPI使用httpclient适配器执行httppost
SOAP响应(状态400):

我建议查看PHP代码发送的XML,然后将其与Ruby Savon代码发送的XML进行比较,并检查差异在哪里。然后看看是否可以修改ruby代码以生成正确的请求

我建议查看PHP代码发送的XML,然后将其与Ruby Savon代码发送的XML进行比较,并检查差异在哪里。然后看看是否可以修改ruby代码以生成正确的请求

告诉Savon使用SOAP版本2(实际上是1.2版),然后手动将内容类型设置为text/xml,这有点违背了目的

如果您的web服务需要SOAP1.2,那么它需要“application/SOAP+xml”的内容类型,如果您将SOAP\u版本设置为2,SAVON将为您提供这种内容类型


如果您想要文本/xml的内容类型,只需将soap_version config变量设置为1,告诉Savon使用soap version 2(实际上是1.2),然后手动将内容类型设置为text/xml就有点达不到目的

如果您的web服务需要SOAP1.2,那么它需要“application/SOAP+xml”的内容类型,如果您将SOAP\u版本设置为2,SAVON将为您提供这种内容类型


如果您想要文本/xml的内容类型,只需将soap_version config变量设置为1即可。我发现我需要添加标题以通过415错误


Savon.client(wsdl:“www.sample_doman.com/endpoint?wsdl”,标题:{'Content-Type'=>'application/soap+xml;charset=utf-8'})

我发现我需要添加标题才能通过415错误

客户端(wsdl:“www.sample_doman.com/endpoint?wsdl”,标题:{'Content-Type'=>'应用程序/soap+xml;charset=utf-8'})

POST /V2.0/Logon.svc HTTP/1.1
Host: api.affili.net
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.0-8+etch16
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://affilinet.framework.webservices/Svc/ServiceContract1/Logon"
Content-Length: 456

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://affilinet.framework.webservices/types"
    xmlns:ns2="http://affilinet.framework.webservices/Svc"
>
    <SOAP-ENV:Body>
        <ns2:LogonRequestMsg>
            <ns1:Username>xxx</ns1:Username>
            <ns1:Password>yyy</ns1:Password>
            <ns1:WebServiceType>Product</ns1:WebServiceType>
        </ns2:LogonRequestMsg>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP request: https://api.affili.net/V2.0/Logon.svc
Content-Type: text/xml; charset=utf-8, SOAPAction: http://affilinet.framework.webservices/Svc/ServiceContract1/Logon, Content-Length: 605

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsdl="http://affilinet.framework.webservices/Svc"
    SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://affilinet.framework.webservices/types"
    xmlns:ns2="http://affilinet.framework.webservices/Svc"
>
    <SOAP-ENV:Body>
        <ns2:LogonRequestMsg>
            <ns1:Username>XXX</ns1:Username>
            <ns1:Password>YYY</ns1:Password>
            <wsdl:WebServiceType>Product</wsdl:WebServiceType>
        </ns2:LogonRequestMsg>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


HTTPI executes HTTP POST using the httpclient adapter
SOAP response (status 400):