例如,我如何从 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/