rubysoapsavon

Savon - SOAP - ruby - 400 Bad Request


I'm trying to use Savon to make a SOAP request with Ruby, but I'm receiving a 400 Bad Request response from the server.

This is the request I'm trying to make (according to soapUI):

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:apis="http://www.csisoftwareusa.com/ApiService">    
    <soap:Header/>    
    <soap:Body>
      <apis:AuthenticateConsumer>
         <!--Optional:-->
         <apis:consumerName>?</apis:consumerName>
         <!--Optional:-->
         <apis:consumerPassword>?</apis:consumerPassword>
      </apis:AuthenticateConsumer>    
    </soap:Body> 
</soap:Envelope>

Here is the request that I make with Ruby; it returns a 400 Bad Request error:

<SOAP-ENV:Envelope>
  <SOAP-ENV:Body>
    <ins0:AuthenticateConsumer>
      <ins0:consumerName>?</ins0:consumerName>
      <ins0:consumerPassword>?</ins0:consumerPassword>
    </ins0:AuthenticateConsumer>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Http Headers: SOAPAction: "http://www.csisoftwareusa.com/ApiService/AuthenticateConsumer", Content-Type: text/xml;charset=UTF-8, Content-Length: 504

Here is the request that I was able to make with Python. THIS request succeeds:

<SOAP-ENV:Envelope>
  <SOAP-ENV:Header/>
  <ns0:Body>
    <ns1:AuthenticateConsumer>
      <ns1:consumerName>?</ns1:consumerName>
      <ns1:consumerPassword>?</ns1:consumerPassword>
    </ns1:AuthenticateConsumer>
  </ns0:Body>
</SOAP-ENV:Envelope>
Http headers: {'SOAPAction': u'"http://www.csisoftwareusa.com/ApiService/AuthenticateConsumer"', 'Content-Type': 'text/xml; charset=utf-8'}

I need to integrate calls to this API into a Rails application, so doing it in Python isn't a valid solution.

I'm wondering if anyone can see what I'm missing. Is the empty <SOAP-ENV:Header /> tag the issue, and if so, how can I add that to the Savon request?

Thanks, Stuart


Solution

  • The issue here is with my http headers: Because the url has spaces in it, the url has to be encoded. However, I have to encode it before passing it to Savon, which then encodes it again - this double-encoded url fails. See: https://stackoverflow.com/questions/14482251/ruby-savon-soap-request-double-escapes-spaces-in-url

    Thanks, Stuart