title: Sending data from Java to PHP via POST
body: <p>On one side I have a Java program that keeps feeding a database. On the other a web server (Apache). I need to transfer multiple entries, at once, from the program to a distant web server via a REST webservice. 
   While I have no trouble to send pairs of values from one to the others (using a HttpClient on the Java's side and a PHP file that writes into the server's own database on the other side), I lack knowledge about how I could build my HTTP request with data.</p>
  
  <p>I've been using an Entity so far :</p>
  
  <pre><code>List&lt;NameValuePair&gt; list = new ArrayList&lt;NameValuePair&gt;();
  list.add(new BasicNameValuePair("field1", "aaa"));
  list.add(new BasicNameValuePair("field2", "bbb"));
  
  httppost.setEntity(new UrlEncodedFormEntity(list));
  </code></pre>
  
  <p>and receiving it in my PHP file :</p>
  
  <pre><code>&lt;?php
      $field1=$_POST["field1"];
      $field2=$_POST["field2"];
      $con= mysql_connect("localhost","root");
      if(!$con) die("Not able to connect");
      mysql_select_db("mydb",$con);
      mysql_query("INSERT INTO `mytable` (`field1`, `field2`) VALUES ('$field1', '$field2')");
      mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>Works great. Simple and easy. But now, as stated before, I wish to transfer several entries from my database. Each entry consists of 35 fields, which yields to some big data.</p>
  
  <p><em>My question is :</em> <strong>How</strong> can I insert my database entries within ONE (or as many as needed if one HTTP request capacity is full) and fetch the resulting data on the PHP file side ?
  Bonus : with the previous solution, how can I compress that data?</p>