收到从Java DataOutputStream类输出一个PHP页面 [英] receive output from java DataOutputStream in a php page

查看:186
本文介绍了收到从Java DataOutputStream类输出一个PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用的文件发送回我的服务器的Java小程序 - 在服务器端我想收到这样的PHP页面上。

I have a java applet which I am using to send a file back to my server with - on the server end I want to receive this on a php page.

下面是java code这是做信息的发送,对事情我已经检查了全局数组PHP端和我的URL传递的数据,而不是文件数据。我真的搜查,在抓这一个,所以任何帮助AP preciated。

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. I have really searched and scratched on this one so any help appreciated.

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();


解决 - 正如经常发生的奋力拼杀和仅仅几分钟几天后的一个职位的问题后的解决方案presents


SOLVED - as so often happens one posts a question after days of battling and mere minutes later a solution presents.

我如何使用SOAP,我用卷曲的前一次传输的XML数据想起了评论之后思考。一些搜索后,我遇到了一个更简单,非常优雅的解决方案。

I got thinking after the comment about using SOAP that I remembered using cURL for transferring XML data once before. a few searches later and I came across a much simpler and very elegant solution.

http://www.lornajane.net/文章/ 2008 /访问 - 来电-PUT-数据从-PHP

基本上可以通过访问在PHP中PUT数据

basically you can access the PUT data in php by using

file_get_contents("php://input")

所以现在它的作品赫然

so now it works awesomely

推荐答案

我用了很多次的SOAP消息来获取数据从PHP到Java的正常工作

i used a lot of times Soap Messages to get Data From PHP to Java that works fine

所以使用PHP作为web服务并通过SOAP通信

So Use PHP as Webservice and Communicate via SOAP

设置WSDL文件

生成Java存根和骨架
http://download.oracle.com/javase/6 /docs/technotes/tool​​s/share/wsimport.html

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

WSDL加载到一个PHP skript
http://www.php.net/manual/de/book.soap.php

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

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

和做你的逻辑在PHP

And do your logic in the php

然后使用Java存根调用服务器和传输数据

Then use the Java Stubs to call the server and transmit your data

这篇关于收到从Java DataOutputStream类输出一个PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆