can php get a $_post direct from an applet?
Posted: Wed Jun 03, 2009 2:41 pm
Hi, I've been learning a bit of php and starting to rely on it in my web pages, but I want to get an old applet to save images to the site (http://www.ballooncalculus.org/forum/top.php). Can't seem to get off the ground with configuring servlets to save files, but this old post http://www.sum-it.nl/en200141.html tells me I can send data direct from the applet to a php page. That would be swell. No joy yet, though, with this alleged code for the applet:
The post didn't tell me how the php page should look, but I tried...
This page shows no sign of having been woken up by the connection - and the connection did get created successfully, I think - the applet didn't complain that it couldn't find the php page. The post did tell me to expect the php page to receive a $_POST, but I can't see any $_POSTs in my logs. Is there a more sensible way to approach the php end - or either end? Excuse my ignorance... grateful for any advice.
Tom
Code: Select all
URL url;
URLConnection con;
OutputStream oStream;
String parametersAsString;
byte[] parameterAsBytes;
String aLine; // only if reading response
parametersAsString = "msg=hello&to=world";
parameterAsBytes = parametersAsString.getBytes();
// send parameters to server
url = this.getCodeBase();
url = new URL(url + "index.php3");
con = url.openConnection();
con.setDoOutput(true);
// setDoInput(true); // only if reading response
con.setDoInput(false);
con.setRequestProperty("Content=length", String.valueOf(parameterAsBytes.length));
oStream = con.getOutputStream();
oStream.write(parameterAsBytes);
oStream.flush();
oStream.close();Code: Select all
<?php
$str = "post?... ";
if ($_POST) {
$str .= print_r($_POST);
} else {
$str .= "apparently not";
}
echo file_put_contents("savings.txt", str);
?>Tom