title: How to send string compressed with GZIP from Java App to PHP web service
body: <p>I have this issue with GZIP compression:</p>
  
  <p>I need to send by POST method a huge JSON string, which is too big to be accept like URL (Ex: <a href="http://localhost/app/send/" rel="nofollow">http://localhost/app/send/</a><strong>JSON STRING ENCODED BY BASE64</strong>), than it result in HTTP error 403</p>
  
  <p>so, I need to compress my json and I found a way to do it with GZIP compression, which I can decompress with gzdecode() in PHP.</p>
  
  <p>but it doesn't work...</p>
  
  <p>my functions compress() and decompress() works fine inside my Java App, but when I send it to webservice, something goes wrong and gzdecode() doesn't work. 
  I have no idea what I missing, I need some help</p>
  
  <p>functions used in java app (client)</p>
  
  <pre><code>    public String Post(){
       String retorno = "";
       String u = compress(getInput());
       u = URLEncoder.encode(URLEncoder.encode(u, "UTF-8"));
  
       URL uri = new URL(url + u);
  
       HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
  
       conn.setDoOutput(false);
       conn.setRequestMethod(getMethod());
  
       conn.setRequestProperty("Content-encoding", "gzip");
       conn.setRequestProperty("Content-type", "application/octet-stream");
  
       BufferedReader buffer = new BufferedReader(
                      new InputStreamReader((conn.getInputStream())));
  
       String r = "";
       while ((r = buffer.readLine()) != null) {
                  retorno = r + "\n";
       }
       return retorno;
  }
  </code></pre>
  
  <p>GZIP compress function (client)</p>
  
  <pre><code>public static String compress(String str) throws IOException {
  
          byte[] blockcopy = ByteBuffer
                  .allocate(4)
                  .order(java.nio.ByteOrder.LITTLE_ENDIAN)
                  .putInt(str.length())
                  .array();
          ByteArrayOutputStream os = new ByteArrayOutputStream(str.length());
          GZIPOutputStream gos = new GZIPOutputStream(os);
          gos.write(str.getBytes());
          gos.close();
          os.close();
          byte[] compressed = new byte[4 + os.toByteArray().length];
          System.arraycopy(blockcopy, 0, compressed, 0, 4);
          System.arraycopy(os.toByteArray(), 0, compressed, 4,
                  os.toByteArray().length);
  
          return Base64.encode(compressed);
  
      }
  </code></pre>
  
  <p>method php used to receive a URL (server, using Slim/PHP Framework)</p>
  
  <pre><code>init::$app-&gt;post('/enviar/:obj/', function( $obj ) {
       $dec = base64_decode(urldecode( $obj ));//decode url and decode base64 tostring
       $dec = gzdecode($dec);//here is my problem, gzdecode() doesn't work
  }
  </code></pre>
  
  <p>post method</p>
  
  <pre><code>public Sender() throws JSONException {   
      //
      url = "http://192.168.0.25/api/index.php/enviar/";
      method = "POST";
      output = true;
      //
  }
  </code></pre>