1

I am making a SOAP call with using a Ruby On Rails gem Savon and when making a request, I get this error message:

Bad Request - Invalid Header
HTTP Error 400. The request has an invalid header name.

It sounds pretty descriptive, but I am still not able to figure out the problem. I also found a few topics here on SO, but none of them has unfortunately helped me.

Here's how I do make the connection:

client = Savon.client(endpoint: wsdl_url,
                          namespace: '',
                          env_namespace: :s, 
                          basic_auth: ["username", "password"],
                          ssl_verify_mode: :none,
                          log: true,
                          logger: Rails.logger,
                          pretty_print_xml: true)

@response = client.call('MyAction', 
                        soap_action: 'url address',
                        xml: xml_payload,
                        headers: {
                          'Content-Type': 'application/soap+xml; charset=utf-8',
                        })

And here's the generated error from the (terminal) console:

SOAP response (status 400)
<?xml version="1.0"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
  <HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"/>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP Error 400. The request has an invalid header name.</p>
</hr></BODY>
</HEAD>
</HTML>

If I change the header config from this:

@response = client.call('MyAction', 
                            soap_action: 'url address',
                            xml: xml_payload,
                            headers: {
                              'Content-Type': 'application/soap+xml; charset=utf-8',
                            })

to this:

@response = client.call('MyAction', 
                            soap_action: 'url address',
                            xml: xml_payload)

The error message says a lot less:

Savon::HTTPError - HTTP error (400):

So the header makes it a bit more descriptive. If I look at the headers generated by Savon, it looks like this:

SOAP request: https://URL_ENDPOINT
Content-Type: application/soap+xml; charset=utf-8, SOAPAction: "http://URL_ENDPOINT/MyAction", Content-Type: text/xml;charset=UTF-8, Content-Length: 2935

What headers are wrong? How do I debug/inspect it here?

I also tried to investigate this issue in Postman and got only this error message:

400 Bad Request - The request cannot be fulfilled due to bad syntax.

I also tried to validate the generated XML data I send to the server - and that's valid (verified on different validators).

How do I solve this problem?

Thank you

user984621
  • 46,344
  • 73
  • 224
  • 412

0 Answers0