簡體   English   中英

在 php 頁面中從 java DataOutputStream 接收 output

[英]receive output from java DataOutputStream in a php page

我有一個 java 小程序,我用它來將文件發送回我的服務器,在服務器端我想在 php 頁面上接收它。

Below is the java code which is doing the sending, on the php side of things I have checked the global arrays and I have the data passed by the URL, but not the file data. 我真的在這個上進行了搜索和抓撓,所以任何幫助表示贊賞。

String strURL = sendToURL + "?ACTION=POST&LEN=" + imgBytes.length + "&Fname=picture.png";
    try{
        URL urlServlet = new URL(strURL);
        URLConnection sCon = urlServlet.openConnection();
        sCon.setDoInput(true);
        sCon.setDoOutput(true);
        if (sCon.getAllowUserInteraction()) {
            sCon.setAllowUserInteraction(true);
        }
        sCon.setUseCaches(false);
        sCon.setDefaultUseCaches(false);
        sCon.setRequestProperty("Content-Type", "text/html");
        sCon.setRequestProperty("Connection", "Keep-Alive");
        sCon.setConnectTimeout(transferTimeout);
        sCon.setReadTimeout(transferTimeout);
        DataOutputStream out = new DataOutputStream(sCon.getOutputStream());

        int index = 0;
        size = 1024;
        do {
            if (index + size > imgBytes.length) {
                size = imgBytes.length - index;
            }
            out.write(imgBytes, index, size);
            index += size;
        } while (index < imgBytes.length);

        out.write(imgBytes);
        out.flush();
        out.close();

已解決 - 通常情況下,一個人在經過幾天的戰斗后發布一個問題,幾分鍾后就會出現一個解決方案。

在關於使用 SOAP 的評論后,我想到了使用 cURL 傳輸 XML 數據一次。 幾次搜索后,我遇到了一個更簡單且非常優雅的解決方案。

http://www.lornajane.net/posts/2008/Accessing-Incoming-PUT-Data-from-PHP

基本上你可以使用 php 訪問 PUT 數據

file_get_contents("php://input")

所以現在它工作得非常好

我多次使用 Soap 消息從 PHP 到 Java 獲取數據,效果很好

所以使用 PHP 作為 Web 服務並通過 SOAP 進行通信

設置 WSDL 文件

Generate Java Stubs and Skeletons http://download.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

Load WSDL into a php skript http://www.php.net/manual/de/book.soap.php

   $soapClient = new SoapClient("blahblah.wsdl"); 

並在 php 中執行您的邏輯

然后使用 Java Stubs 調用服務器並傳輸您的數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM