Soap - PHP 中的 base64binary 数据 [英] Soap - base64binary data in PHP

查看:18
本文介绍了Soap - PHP 中的 base64binary 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 PHP 编写的 SOAP 客户端,可以调用 WSDL 服务.其中一个函数返回base64binary 数据.我一直在尝试解码它,但没有任何运气.

I have a SOAP client in PHP that makes calls to a WSDL service. One of the functions returns a base64binary data. I've been trying to decode it without any luck.

base64_decode($encoded_base64data) 不起作用.我尝试使用带有各种参数的 base_convert() 和 mv_convert_encoding(),但无法获得正确的结果.

base64_decode($encoded_base64data) will not work. I tried using base_convert() and mv_convert_encoding() with various parameters, but could not get a proper result.

编码后的结果数据以:

��`I�%&/m�{J�J��t��`$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�N'���?fdl��J�ɞ!���?~|?"

(数据要长很多,这只是字符串的一小部分)

(the data is much longer, this is just a small portion of the string)

知道怎么做吗?

谢谢

编辑

我使用新的 __doRequest() 方法扩展了 SoapClient,以检查接收到的数据是否是正确的 base64 字符串.我得到了一个正确的 base64 编码字符串,上面显示的结果是解码后的响应.

I've extended the SoapClient with a new __doRequest() method to check that the received data is a proper base64 string. I got a proper base64 encoded string, and the result shown above is the decoded response.

无论如何,字符串由 SoapClient 自动从 base64 解码为二进制(如@hakre 建议的那样),所以我只需要处理二进制响应.

Anyhow, the string was decoded automatically by the SoapClient from base64 to binary (as @hakre suggested), so I only have to deal with the binary response.

现在我需要的是将二进制字符串解码成看起来像可读格式的东西.最终响应应包含格鲁吉亚语输出,因此我试图找出原始编码(但这是一个不同的问题).

Now what I need is to decode the binary string into something that would look like a readable format. The final response should contain Georgian output, so I'm trying to figure out the original encoding (but that's a different question).

推荐答案

来自 base64Binary(XML 架构第 2 部分:数据类型 3.2.16):

[定义:] base64Binary 表示 Base64 编码的任意二进制数据.价值空间base64Binary 是二进制八位字节的有限长度序列的集合.对于base64Binary数据,整个二进制流使用[RFC 2045] 的第 6.8 节.

[Definition:] base64Binary represents Base64-encoded arbitrary binary data. The value space of base64Binary is the set of finite-length sequences of binary octets. For base64Binary data the entire binary stream is encoded using the Base64 Content-Transfer-Encoding defined in Section 6.8 of [RFC 2045].

你然后评论:

当 WSDL 具有 xsd:base64binary 时,我应该得到 base64 响应还是二进制响应或 base64 编码字符串?

When a WSDL has xsd:base64binary am I supposed to get a base64 response or a binary response or a base64 encoded string?

你应该得到一个 base64 编码的字符串.这个 base64 编码的字符串代表二进制数据.如果您了解 XML 规范,这可能会更明显,因为您不能使用 XML 传递二进制信息,您只能传递适合 XML 字符范围的信息.并且该范围不包括作为二进制数据一部分的字符,尤其是控制字符和较高的窗格,如果您将二进制八位字节分为较低和较高的一个.请参阅字符(可扩展标记语言 (XML) 1.0(第五版)2.2) 这表明 XML 是关于字符的,而不是二进制数据.并且还显示了这些字符形成的二进制数据(以及它们不能形成的二进制数据).

You are supposed to get a base64 encoded string. That base64 encoded string represents the binary data. If you know the XML specification, this might be more obvious because you can not pass binary information with XML, you can only pass information that fit's into XML's character-range. And that range excludes characters that are part of binary data, especially control characters and the higher pane if you divide the binary octet into a lower and higher one. See Characters (Extensible Markup Language (XML) 1.0 (Fifth Edition) 2.2) which shows that XML is about characters, not binary data. And which also shows which binary data those characters do form (and which they can not form).

因此,base64Binary 编码被定义为一种在 XML 文档中传输二进制数据的方法.因此,您在 SOAP 请求的原始 XML 响应中获得的内容绝不是二进制,而是 base64 编码的二进制数据.

Therefore the base64Binary encoding has been defined as one way to transport binary data within an XML document. So what you've got inside the raw XML response to your SOAP request is never binary but base64 encoded binary data.

注意您的 SOAP 客户端可能已经处理了这种编码并提供解码的数据.

Take care that your SOAP-client might already deal with this encoding and provide the data decoded.

这篇关于Soap - PHP 中的 base64binary 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆