香皂 - 在PHP中使用Base64Binary数据 [英] Soap - base64binary data in PHP

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

问题描述

我在PHP中的SOAP客户端,使一个WSDL服务电话。其中一个功能返回使用Base64Binary 数据。我一直在试图去code它没有任何运气。

base64_de code($连接coded_base64data)将无法工作。我试着用base_convert()和mv_convert_encoding()与各种参数,但不能得到正确的结果。

在EN codeD结果数据开始:

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

(数据要长得多,这是串的一小​​部分)

任何想法可能怎么做?

感谢

修改

我已经延长了SoapClient的一个新的__doRequest()方法来检查接收到的数据是正确的BASE64字符串。我有一个适当的base64连接codeD字符串,上面显示的结果是德codeD回应。

总之,字符串是德codeD自动被从SoapClient的的base64二进制(如@hakre建议),所以我只需要处理的二进制响应。

现在我需要的是脱code中的二进制字符串到的东西,看起来像一个可读的格式。最终响应应该包含格鲁吉亚的输出,所以我试图找出原来的编码(但是这是一个不同的问题)。


解决方案

从的 base64Binary的(XML Schema第二部分:数据类型3.2.16) 的:


  

[定义:] base64Binary的重新presents的Base64恩codeD任意的二进制数据。 base64Binary的价值空间 >是组二​​进制八位位组的有限长度序列。对于 base64Binary的数据的整个二进制流连接使用的Base64中的第6.8 [RFC 2045]


您然后注释:


  

在一个WSDL有XSD:使用Base64Binary我应该得到一个base64反应或二元响应或一个base64 EN codeD字符串


您应该得到一个base64连接codeD字符串。这一带的base64 codeD字符串的再presents 的二进制数据。如果您知道XML规范,因为你无法通过使用XML二进制信息,这可能是比较明显的,你只能通过适合的成XML的字符范围的信息。和在该范围中排除是二进制数据的一部分的字符,尤其是控制字符和更高窗格如果分割二进制八位位组成较低和较高的一个。请参见人物(可扩展标记语言(XML)1.0(第五版)2.2)这表明XML是关于字符,而不是二进制数据。而这也显示了二进制数据,这些字符做形式(以及他们不能形成)。

因此​​<青霉> base64Binary的的编码已被定义为到一个XML文档内传送二进制数据的一种方法。所以,你的原始XML响应您的SOAP请求里面有什么的从不二进制的,但连接的base64 codeD二进制数据。

请小心,您的SOAP客户端的可能的已经处理这个编码和提供数据去codeD。

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) will not work. I tried using base_convert() and mv_convert_encoding() with various parameters, but could not get a proper result.

The encoded result data starts with:

��`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)

Any idea how it could be done?

Thanks

EDIT

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.

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

解决方案

From base64Binary (XML Schema Part 2: Datatypes 3.2.16):

[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].

You then comment:

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

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

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.

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

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

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