肥皂 - 基础64位数据在PHP [英] Soap - base64binary data in PHP

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

问题描述

我在PHP中有一个SOAP客户端,用于调用WSDL服务。其中一个函数返回一个 base64binary 数据。我一直在努力解码它,没有任何运气。



base64_decode($ encoded_base64data)将无法正常工作。我尝试使用base_convert()和mv_convert_encoding()与各种参数,但无法得到正确的结果。



编码结果数据从以下开始:

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

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



任何想法如何才能完成?



谢谢



EDIT



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



无论如何,该字符串被SoapClient从base64自动解码为二进制(如@hakre所建议) ,所以我只需要处理二进制响应/ p>

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

解决方案

p>从 base64Binary(XML Schema Part 2:Datatypes 3.2.16)


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





当WSDL有xsd:base64binary时,我应该得到一个base64响应或一个二进制响应或一个base64编码的字符串

p>

你应该得到一个base64编码的字符串。 base64编码的字符串表示二进制数据。如果您知道XML规范,这可能更为明显,因为您无法使用XML传递二进制信息,因此只能将适合的信息传递到XML的字符范围。并且该范围将排除二进制数据的一部分的字符,特别是控制字符,如果将二进制八位字节划分为较低和较高的字符,则排除较高的窗格。请参阅字符(可扩展标记语言(XML)1.0(第五版)2.2)这表明XML是关于字符,而不是二进制数据。并且还显示这些字符形成的二进制数据(并且它们不能形成)。



因此,base64Binary 编码已被定义为在XML文档中传输二进制数据的一种方式。那么你对SOAP请求的原始XML响应中的内容从来不是二进制的,而是base64编码的二进制数据。



小心你的SOAP-client 可能已经处理了这种编码,并提供了解码的数据。


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.

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

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