使用 Ruby 和 Savon 发送 UTF-16 编码的 SOAP 请求

发布于 2024-12-11 11:02:47 字数 1843 浏览 0 评论 0原文

如何将请求编码为 UTF-16?这是我所拥有的:

  # Create Savon client
  @client = Savon::Client.new do
    wsdl.document = File.expand_path("account_list.wsdl", __FILE__)
  end

  # Set header encoding
  @client.http.headers["Content-Type"] = "text/xml;charset=UTF-16"

  # Setup ssl configuration
  @client.http.auth.ssl.cert_key_file = "cert_key_file.pem"
  @client.http.auth.ssl.cert_file = "cert_file.pem"
  @client.http.auth.ssl.ca_cert_file = "ca_cert_file.pem"
  @client.http.auth.ssl.verify_mode=:none

  # Execute request
  response = @client.request :account_list do
    soap.body = {
      :id => "18615618"
      }
  end

这是发送的内容,请注意编码=“UTF-8”:

Content-Type: text/xml;charset=UTF-16, SOAPAction: "accountList", Content-Length: 888 <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema

这是我得到的错误:

< s o a p : E n v e l o p e   x m l n s : s o a p = " h t t p : / / s c h e m a s . x m l s o a p . o r g / s o a p / e n v e l o p e / "   x m l n s : w s>d
 < s o a p : B o d y >
   < s o a p : F a u l t >
     < f a u l t c o d e > s o a p : C l i e n t < / f a u l t c o d e >
     < f a u l t s t r i n g > F a i l e d   t o   p r o c e s s   S O A P   r e q u e s t .   S O A P   b o d y   n o t   i n   U T F - 1 6 .
< / f a u l t s t r i n g >
     < d e t a i l >
       < w s d l _ o p s : e r r o r > F a i l e d   t o   p r o c e s s   S O A P   r e q u e s t .   S O A P   b o d y   n o t   i n   U T F - 1 6 .
< / w s d l _ o p s : e r r o r >
     < / d e t a i l >
   < / s o a p : F a u l t >
 < / s o a p : B o d y >
< / s o a p : E n v e l o p e >

How do I encode the request in UTF-16? Here's what I have:

  # Create Savon client
  @client = Savon::Client.new do
    wsdl.document = File.expand_path("account_list.wsdl", __FILE__)
  end

  # Set header encoding
  @client.http.headers["Content-Type"] = "text/xml;charset=UTF-16"

  # Setup ssl configuration
  @client.http.auth.ssl.cert_key_file = "cert_key_file.pem"
  @client.http.auth.ssl.cert_file = "cert_file.pem"
  @client.http.auth.ssl.ca_cert_file = "ca_cert_file.pem"
  @client.http.auth.ssl.verify_mode=:none

  # Execute request
  response = @client.request :account_list do
    soap.body = {
      :id => "18615618"
      }
  end

Here's the begging of what's sent, notice the encoding="UTF-8":

Content-Type: text/xml;charset=UTF-16, SOAPAction: "accountList", Content-Length: 888 <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema

Here's the error I get:

< s o a p : E n v e l o p e   x m l n s : s o a p = " h t t p : / / s c h e m a s . x m l s o a p . o r g / s o a p / e n v e l o p e / "   x m l n s : w s>d
 < s o a p : B o d y >
   < s o a p : F a u l t >
     < f a u l t c o d e > s o a p : C l i e n t < / f a u l t c o d e >
     < f a u l t s t r i n g > F a i l e d   t o   p r o c e s s   S O A P   r e q u e s t .   S O A P   b o d y   n o t   i n   U T F - 1 6 .
< / f a u l t s t r i n g >
     < d e t a i l >
       < w s d l _ o p s : e r r o r > F a i l e d   t o   p r o c e s s   S O A P   r e q u e s t .   S O A P   b o d y   n o t   i n   U T F - 1 6 .
< / w s d l _ o p s : e r r o r >
     < / d e t a i l >
   < / s o a p : F a u l t >
 < / s o a p : B o d y >
< / s o a p : E n v e l o p e >

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

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

发布评论

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

评论(1

梦里寻她 2024-12-18 11:02:47

Savon 目前仅支持 更改 XML 指令标签 通过集成的 Builder 方法:

response = @client.request(:account_list) do
  soap.xml(:xml, :encoding => "UTF-16") { |xml| xml.id("18615618") }
end

不过,使用这种方法您会错过很多 XML 支持。没有 SOAP 信封,没有标头或正文:

<?xml version="1.0" encoding="UTF-16"?><id>18615618</id>

我将使用您的票来提出尽快有更好的解决方案!

Savon currently only supports changing the XML directive tag via the integrated Builder-method:

response = @client.request(:account_list) do
  soap.xml(:xml, :encoding => "UTF-16") { |xml| xml.id("18615618") }
end

You'll miss out a lot of XML-support by using this approach though. No SOAP envelope, no header or body:

<?xml version="1.0" encoding="UTF-16"?><id>18615618</id>

I'll use your ticket to come up with a better solution asap!

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