title: php server - java client - post and echo
body: <p>i'm completely new to java, php and so on ... so please forgive my stupid question.</p>
  
  <p>I want to write a PHP server application which receives a name from a Java client application. It should respond printing the name on the output and sending a status message (Write failed/success).</p>
  
  <p>How would I get the Java client send the name and receive the reply from the PHP program, and how would the PHP program receive and print the name and send the reply? I have googled a lot: i have found several code examples but the script doesn't work still.</p>
  
  <p>Trying to make it work i've written the following:</p>
  
  <p><strong>Server Side</strong></p>
  
  <pre><code>    &lt;html&gt;
          &lt;head&gt;
              &lt;title&gt;PHP Giulio&lt;/title&gt;
          &lt;/head&gt;
          &lt;body&gt;   
              &lt;?php
  $username = "Giulio";                
  echo "$username"; 
  $username = $_POST['username'];
  print "$username"; 
              ?&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>in this way i thought that before the server had received the name from the client "Giulio" was printed, while, after having received it, the received name would have been printed.</p>
  
  <p>On the other side</p>
  
  <p><strong>Client Side</strong></p>
  
  <pre><code>import java.io.InputStream;
  import java.io.OutputStreamWriter;
  import java.net.*;
  
  public class JavaPHP {
      public static void main(String[] args){
          URL url;
          try {
              url = new URL("http://www.mydomain.com/myfile.php");
              URLConnection connection = url.openConnection(); 
              connection.setDoOutput(true); 
              OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
              out.write("username=NameToBeWritten");
              out.flush(); 
              out.close(); 
              InputStream in=connection.getInputStream();
              in.read();
              in.close();
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }       
      }
  }
  </code></pre>
  
  <p>well ... i obtain that on the output i see only the name Giulio.
  How can i make it receive and print the sent name?</p>
  
  <p>Please help me</p>
  
  <p>Thanks in advance.</p>
  
  <p>Giulio!!</p>