title: How can I send XML from a Java application and print it with PHP on the server, using HTTP POST?
body: <p>Usually when I get POST data it's send from a HTML form and the parameters has names, i.e. from <code>&lt;input type="text" name="yourname" /&gt;</code>, then I can receive and print this data with php <code>echo $_POST['yourname'];</code>.</p>
  
  <p>Now I am implementing a Java application that should POST data in XML format to a specified URL. I wrote a simple PHP page that I can try to POST data to, but the data is not printed. And since there is no name of any parameters I don't know how I should print it with PHP.</p>
  
  <p>I have tried to send simple XML to the server and the server should respond with <code>MESSAGE: &lt;XML&gt;</code>, but it only response with <code>MESSAGE:</code>. What am I doing wrong?</p>
  
  <p>Here is my PHP-code on the server:</p>
  
  <pre><code>&lt;?php 
  echo 'MESSAGE:';
  print_r($_POST); ?&gt;
  </code></pre>
  
  <p>And here is my Java code on the client:</p>
  
  <pre><code>String xmlRequestStatus = "&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\"?&gt;
      &lt;test&gt;&lt;/test&gt;";
  String contentType = "text/xml";
  String charset = "ISO-8859-1";
  String request = null;
  try {
      request = String.format("%s",
          URLEncoder.encode(xmlRequestStatus, charset));
  } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
  }
  URL url = null;
  URLConnection connection = null;
  OutputStream output = null;
  InputStream response = null;
  try {
      url = new URL("http://skogsfrisk.se/test/");
  } catch (MalformedURLException e) {
      e.printStackTrace();
  }
  
  try {
      connection = url.openConnection();
      connection.setDoOutput(true);
      connection.setRequestProperty("Accept-Charset", charset);
      connection.setRequestProperty("Content-Type", contentType);
      output = connection.getOutputStream();
      output.write(request.getBytes("ISO-8859-1"));
      if(output != null) try { output.close(); } catch (IOException e) {}
  
      response = connection.getInputStream();
      ...
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>