ruby - 如何从 Savon 请求中删除 "SOAPAction"HTTP header

标签 ruby http header savon

例如,我如何从 Savon 请求中删除 HTTP header

client.request 'v5:ProcessShipments' do
  client.http.headers["SOAPAction"] = "example_post"
end

这会生成

DEBUG -- : SOAPAction: example_post

服务器会响应

Server did not recognize the value of HTTP Header SOAPAction: example_post.

但是我不想有任何 SOAPAction

我尝试清除该变量并将其删除。我搜索了一段时间,找不到任何东西,所以我希望以前没有人问过这个问题。

提前致谢。

如果我不覆盖它,那么默认情况下 Savon 将使用 client.request 'v5:ProcessShipments',这也是不正确的。

最佳答案

这里引用 savon documentation供将来引用:

SOAPAction is an HTTP header information required by legacy services. If present, the header value must have double quotes surrounding the URI-reference (SOAP 1.1. spec, section 6.1.1).

通过阅读 savon 源代码,我发现 Savon::Client#request 方法在生成 block 之前自动设置“SOAPAction” header 。我尝试删除 SOAPAction header ,它起作用了:

require 'savon'

client = Savon::Client.new do
  wsdl.document = "test.wsdl"
end

client.request :wsdl, "sayHello" do
    http.headers.delete("SOAPAction")
end 

这是它生成的请求:

SOAP request: http://www.examples.com/SayHello/
DEBUG -- : Content-Type: text/xml;charset=UTF-8, Content-Length: 332
DEBUG -- : 
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xmlns:wsdl="http://www.examples.com/wsdl/HelloService.wsdl"
                            xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
        <wsdl:sayHello></wsdl:sayHello>
    </env:Body>
</env:Envelope>

如您所见,没有 SOAPAction HTTP header 。

HTH

关于ruby - 如何从 Savon 请求中删除 "SOAPAction"HTTP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8524317/

相关文章:

Ruby:代码 "updgrading"从 1.8.6 到 1.9.2

ruby-on-rails - Assets 管道图像子目录 heroku

java - 使用 Java 以编程方式下载 CSV 文件

ios - Xcode 找不到头文件

php - 使用 MySQL 表值作为标题

ruby-on-rails - 通过 ruby​​ 代码读取和更新 YAML 文件

ruby - 如何用不在引号中的冒号分隔字符串

java - 出现不明字符时,如何将URL转为URI?

python - HTTP 服务器在接受数据包时挂起

PHP header 没有重定向,但是前面没有输出