如何删除“SOAPAction”来自 Savon 请求的 HTTP 标头

发布于 2024-12-21 21:43:50 字数 530 浏览 0 评论 0原文

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

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',这也是不正确的。

How would I remove the HTTP headers from a Savon request for example

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

This would generate

DEBUG -- : SOAPAction: example_post

And the server would respond

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

However I dont want to have any SOAPAction(s)

I have tried to clear the variable and delete it. I search for a while and couldn't find anything so I hope this hasn't been asked before.

Thanks in advance.

If I dont override it then by default Savon will use the client.request 'v5:ProcessShipments', which is also incorrect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小镇女孩 2024-12-28 21:43:50

以下是 savon 文档 的引用,供将来参考:

SOAPAction 是遗留服务所需的 HTTP 标头信息。
如果存在,标头值必须用双引号引起来
URI 引用(SOAP 1.1. 规范,第 6.1.1 节)。

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

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 标头。

华泰

Here is a quote from savon documentation for the future references:

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).

By reading savon source code I figured out that Savon::Client#request method sets "SOAPAction" header automatically before it yields a block. I tried to delete SOAPAction header and it worked:

require 'savon'

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

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

Here is the request it generates:

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>

As you can see there is no SOAPAction HTTP header.

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文