問題描述
我有一個使用 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 數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!