2011-11-05 104 views
1

我正在尝试使用Ruby库Savon进行SOAP请求。Ruby:Savon SOAP请求收到400和415错误

我使用下面的代码:

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' 
)); 

任何人都可以点我朝着正确的方向有什么可能的误差源可能是什么?我现在完全失去了。

谢谢你的帮助。


我一样汤姆·德列伊建议,并试图删除的问题,尽可能产生SOAP请求尽可能多的不同之处。但我仍然收到400错误。任何暗示可能的原因将不胜感激。 (再次,XML换行符添加为了清楚)

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> 

这是由红宝石产生的(不工作)请求:

这是由PHP产生的(工作)请求(在XML换行符添加为了清楚)

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): 

回答

2

我建议在看由PHP代码发送的XML,然后将其与由红宝石萨翁代码发送的XML比较,并检查其中的差异。然后看看你是否可以修改你的ruby代码来生成正确的请求。

0

告诉Savon使用SOAP版本2(确实是1.2),然后手动将内容类型设置为text/xml类型会使目标失败。

如果你的Web Service需要SOAP 1.2,那么如果你如果你想设置的soap_version为2

它期待“应用程序/肥皂+ XML”,这SAVON会为你做的内容类型内容类型的文本/ XML,只需将您的soap_version配置变量设置为1

2

我发现我需要添加标题以获取415错误。

Savon.client(WSDL: “www.sample_doman.com/endpoint?wsdl”,标头:{ '的Content-Type'=> '应用/肥皂+ xml的;字符集= UTF-8'})