我有一个java applet,我用来将文件发送回我的服务器 - 在服务器端我希望在php页面上收到这个。
下面是正在进行发送的java代码,在php方面,我检查了全局数组,并且我有URL传递的数据,但不是文件数据。我真的在这个问题上搜索过,所以任何帮助都是值得赞赏的。
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")
所以现在它的工作非常棒
答案 0 :(得分:0)
我使用了很多次Soap Messages来获取PHP中的数据到Java工作正常
所以使用PHP作为Web服务并通过SOAP进行通信
设置WSDL文件
生成Java Stubs和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
$soapClient = new SoapClient("blahblah.wsdl");
在php中做你的逻辑
然后使用Java Stubs调用服务器并传输数据