Soap - base64 binary data in PHP

I have a SOAP client in PHP that calls WSDL service calls. One of the functions returns base64binary data. I tried to decode it with no luck.

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

Encoded result data starts with:

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

(data is much longer, this is just a small part of the line)

Any idea how this can be done?

thanks

EDIT

I extended SoapClient with a new __doRequest () method to verify that the data received is the correct base64 string. I got the correct base64 encoded string, and the result shown above is a decoded answer.

Anyway, the string was automatically decrypted by SoapClient from base64 to binary (as suggested by @hakre), so I only need to deal with the binary answer.

Now I need to decode the binary string into something that will look like a readable format. The final answer should contain a way out of Georgia, so I'm trying to figure out the source encoding (but that's another question).

+8
soap wsdl php encoding base64
source share
2 answers

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

[Definition:] base64Binary represents arbitrary Base64 encoded binary data. The base64Binary value space is a set of sequences of finite length 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] .

Then you will comment:

When WSDL has xsd: base64binary am, should I get a base64 response or a binary response or base64 encoding?

It is supposed to get a base64 encoded string. This base64 encoded string represents binary data. If you know the XML specification, this may be more obvious, because you cannot transmit binary information using XML, you can only transmit information that fits into the XML range of characters. And this range excludes characters that are part of binary data, especially control characters and the top bar, if you split the binary octet into a lower and a higher one. See Symbols (Extensible Markup Language (XML) 1.0 (fifth edition) 2.2) , which shows that XML is symbols, not binary data. It also shows which binary data these characters form (and which they cannot form).

Therefore, base64Binary encoding was defined as one of the ways to transfer binary data in an XML document. Thus, what you received inside the raw XML response to your SOAP request is never binary, but base64 encoded binary data.

Make sure that your SOAP client has already dealt with this encoding and provides data decoding.

+11
source share

Although the previous answer is absolutely correct, but I believe that this can be useful for a quick solution.

When we check the xml response, we see the data encoded by base64, and we try to decode it in our code to get real data, but this is not required.

Remove base64_decode .

Because the SOAP client internally decodes itself.

+6
source share

All Articles