【发布时间】:2012-12-02 21:54:37
【问题描述】:
我正在尝试使用 Savon 通过 Ruby 发出 SOAP 请求,但我收到了来自服务器的 400 Bad Request 响应。
这是我试图提出的请求(根据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>
这是我对 Ruby 提出的要求;它返回 400 Bad Request 错误:
<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
这是我能够用 Python 提出的请求。此请求成功:
<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'}
我需要将对该 API 的调用集成到 Rails 应用程序中,因此在 Python 中执行此操作不是一个有效的解决方案。
我想知道是否有人能看到我缺少的东西。空的<SOAP-ENV:Header /> 标记是否是问题所在,如果是,我如何将其添加到 Savon 请求中?
谢谢, 斯图尔特
【问题讨论】:
-
你的 ruby 示例中的
</SOAP-ENV:Envelope>>是什么?好像你有无效的xml。你真的应该使用像 Nokogiri 这样的 xml 构建器来构建它 -
@MichaelPapile 显然这是我对 StackOverflow 问题的格式的拼写错误;我重新运行了查询,最后一个括号不存在。我已经编辑了问题的文本来解决这个问题。谢谢!
-
这方面有什么更新吗?我正在为同样的事情而苦苦挣扎。使用 Savon Gem 的第 2 版
-
@YeomansLeo 原来我的问题出在 http 标头中;我专门为此发布了一个新问题。 stackoverflow.com/questions/14482251/…