2010-11-13 327 views
1

我正在寫一個與SOAP客戶端(內部使用java)接口的php腳本。java.lang.String不能轉換爲java.io.InputStream

其中一個調用要求我傳遞Base64編碼的內容。

我傳遞這樣的:

(Edit 1) 
$content=file_get_contents('fileX'); 
fileX is a binary file which has been uploaded via POST and saved successfully in /tmp. 
It is ~600kb in binary form. 

$args[]=array('name'=>'content', 'value'=>base64_encode($content), 'type'=>'Base64Binary'); 

但是,我發現了一個錯誤:

java.lang.String cannot be cast to java.io.InputStream 


(Edit2) 
The documentation of the third party application says exactly: 
Parameter Description        Type 
filename The name of the presentation file   String 
      including the file extension. 
content  The content of the presentation file  Base64Binary 
      encoded in Base64 scheme. 
+0

什麼是'$ content'的類型? – 2010-11-13 15:23:43

+0

@evan - 請參閱edit1 – siliconpi 2010-11-13 15:31:13

+2

看起來像Java代碼,而不是PHP,是問題所在。 Java可能期望一個Stream而不是一個字符串。你可以發表解析這個數組的Java片嗎? – 2010-11-13 15:36:36

回答

0

所述陣列中的第二個參數是字符串類型,由於輸出類型爲base64_decode。 Java錯誤意味着它期待InputStream類型的對象。

您可能需要使用Zend PHP的Java大橋在這裏看到:

https://fosswiki.liip.ch/display/~chregu/Convert+PHP+String+to+a+Java+InputStream

以該字符串轉換爲一個Java的InputStream。

下載Zend服務器的位置:

http://www.zend.com/en/products/server/downloads

或替代PHP Java Bridge的位置:

http://php-java-bridge.sourceforge.net/pjb/installation.php

+0

Hi @evan - 你確定嗎?我不想安裝/設置任何一個功能。有沒有更好的辦法? (請參閱編輯2) – siliconpi 2010-11-13 16:27:15

+0

您可以嘗試從'fopen()'傳遞值,並查看Java是否識別格式。我不確定這是否會奏效。 – 2010-11-13 16:29:52

相關問題