如何使用 Savon 将属性添加到标头标签?

发布于 2024-11-18 20:23:48 字数 1177 浏览 2 评论 0原文

我的 SOAP 文档中的标头需要具有如下属性:

<soap:Header>
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
  <eWAYCustomerID>string</eWAYCustomerID>
  <Username>string</Username>
  <Password>string</Password>
</eWAYHeader>

eWAYHeader 需要 xmlns 属性。

我已经尝试过了,

    def create_customer(customer, card)
    response = @client.request(:create_customer, "xmlns" => "https://www.eway.com.au/gateway/managedpayment") do
      soap.header = header
      soap.body = create_customer_body(customer, card)
    end
  end

  private

  def header
    {
      "eWAYHeader" => {
        :attributes! => { :xmlns => 'http://www.eway.com.au/gateway/managedpayment' },
        "eWayCustomerID" => '87654321',
        "Username" => '[email protected]',
        "Password"=> 'test123'
      }
    }
  end

但是属性!输入被忽略。

Soap.header 只接受哈希作为参数,所以我不能只使用字符串设置它的值。

我如何在 Savon 中实现这一目标?

谢谢,

马丁

The header in my SOAP doc needs to have an attribute like this:

<soap:Header>
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
  <eWAYCustomerID>string</eWAYCustomerID>
  <Username>string</Username>
  <Password>string</Password>
</eWAYHeader>

The eWAYHeader needs an xmlns attribute.

I've tried

    def create_customer(customer, card)
    response = @client.request(:create_customer, "xmlns" => "https://www.eway.com.au/gateway/managedpayment") do
      soap.header = header
      soap.body = create_customer_body(customer, card)
    end
  end

  private

  def header
    {
      "eWAYHeader" => {
        :attributes! => { :xmlns => 'http://www.eway.com.au/gateway/managedpayment' },
        "eWayCustomerID" => '87654321',
        "Username" => '[email protected]',
        "Password"=> 'test123'
      }
    }
  end

but the attributes! entry is ignored.

soap.header will only accept a Hash as an argument so I can't just set it's value using a string.

How do I achieve this in Savon?

thanks,

Martin

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

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

发布评论

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

评论(1

圈圈圆圆圈圈 2024-11-25 20:23:48

你可以通过这样做来实现

soap.header = {
  "eWAYHeader" => {
    "eWayCustomerID" => '87654321',
    "Username" => '[email protected]',
    "Password"=> 'test123'
  },
  :attributes! => {"eWAYHeader" => { :xmlns => 'http://www.eway.com.au/gateway/managedpayment' } }, }

You can achieve by doing this

soap.header = {
  "eWAYHeader" => {
    "eWayCustomerID" => '87654321',
    "Username" => '[email protected]',
    "Password"=> 'test123'
  },
  :attributes! => {"eWAYHeader" => { :xmlns => 'http://www.eway.com.au/gateway/managedpayment' } }, }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文