SOAP:HTTP错误400该请求具有无效的标头名称

问题描述

我正在使用Ruby On Rails gem Savon进行SOAP调用,并且在发出请求时收到以下错误消息:

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

这听起来很具有描述性,但我仍然无法弄清楚问题所在。我还在SO上找到了一些主题,但不幸的是,没有一个主题我有帮助。

这是我进行连接的方式:

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',})

这是(终端)控制台生成错误

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>

如果我从此更改标头配置:

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

对此:

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

错误消息少了很多

Savon::HTTPError - HTTP error (400):

因此标头使其更具描述性。如果我看一下Savon生成的标头,则看起来像这样:

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

哪些标题错误?如何在这里调试/检查?

我还尝试在Postman中调查此问题,并且仅收到以下错误消息:

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

我还尝试验证发送到服务器的生成的XML数据-这是有效的(在不同的验证器上进行了验证)。

我该如何解决这个问题?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)