Soap - base64binary data in PHP

后端 未结 2 806
陌清茗
陌清茗 2020-12-20 16:41

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

相关标签:
2条回答
  • 2020-12-20 17:01

    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.

    0 讨论(0)
  • 2020-12-20 17:26

    Although previous answer is absolutely correct but I feel this may be helpful to get quick solution.

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

    Remove base64_decode.

    Because SOAP client internally decode itself.

    0 讨论(0)
提交回复
热议问题