can php get a $_post direct from an applet?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
espressobongo
Forum Newbie
Posts: 1
Joined: Wed Jun 03, 2009 2:10 pm

can php get a $_post direct from an applet?

Post by espressobongo »

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:

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();
The post didn't tell me how the php page should look, but I tried...

Code: Select all

<?php
    $str = "post?... ";
    if ($_POST) {
        $str .= print_r($_POST);
    } else {
        $str .= "apparently not";
    }
    echo file_put_contents("savings.txt", str);
?>
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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: can php get a $_post direct from an applet?

Post by califdon »

Look into the cURL library. It's probably already part of your PHP installation. Check out http://phpsense.com/php/php-curl-functions.html
Post Reply