note 112200 added to function.gzdecode
| From: | anonymous at dekho-ji dot com | Date: | Thu, 16 May 2013 11:31:38 +0000 |
| Subject: | note 112200 added to function.gzdecode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194823@lists.php.net to get a copy of this message | ||
To decode / uncompress the received HTTP POST data in PHP code, request data coming from Java /
Android application via HTTP POST GZIP / DEFLATE compressed format
1) Data sent from Java Android app to PHP using DeflaterOutputStream java class and received in PHP
as shown below
echo gzinflate( substr($HTTP_RAW_POST_DATA,2,-4) ) . PHP_EOL . PHP_EOL;
2) Data sent from Java Android app to PHP using GZIPOutputStream java class and received in PHP code
as shown below
echo gzinflate( substr($HTTP_RAW_POST_DATA,10,-8) ) . PHP_EOL . PHP_EOL;
From Java Android side (API level 10+), data being sent in DEFLATE compressed format
String body = "Lorem ipsum shizzle ma nizle";
URL url = new URL("http://www.url.com/postthisdata.php");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-encoding", "deflate");
conn.setRequestProperty("Content-type", "application/octet-stream");
DeflaterOutputStream dos = new DeflaterOutputStream(
conn.getOutputStream());
dos.write(body.getBytes());
dos.flush();
dos.close();
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String decodedString = "";
while ((decodedString = in.readLine()) != null) {
Log.e("dump",decodedString);
}
in.close();
On PHP side (v 5.3.1), code for decompressing this DEFLATE data will be
echo substr($HTTP_RAW_POST_DATA,2,-4);
From Java Android side (API level 10+), data being sent in GZIP compressed format
String body1 = "Lorem ipsum shizzle ma nizle";
URL url1 = new URL("http://www.url.com/postthisdata.php");
URLConnection conn1 = url1.openConnection();
conn1.setDoOutput(true);
conn1.setRequestProperty("Content-encoding", "gzip");
conn1.setRequestProperty("Content-type", "application/octet-stream");
GZIPOutputStream dos1 = new GZIPOutputStream(conn1.getOutputStream());
dos1.write(body1.getBytes());
dos1.flush();
dos1.close();
BufferedReader in1 = new BufferedReader(new InputStreamReader(
conn1.getInputStream()));
String decodedString1 = "";
while ((decodedString1 = in1.readLine()) != null) {
Log.e("dump",decodedString1);
}
in1.close();
On PHP side (v 5.3.1), code for decompressing this GZIP data will be
echo substr($HTTP_RAW_POST_DATA,10,-8);
Useful PHP code for printing out compressed data using all available formats.
$data = "Lorem ipsum shizzle ma nizle";
echo "\n\n\n";
for($i=-1;$i<=9;$i++)
echo chunk_split(strtoupper(bin2hex(gzcompress($data,$i))),2," ") . PHP_EOL . PHP_EOL;
echo "\n\n\n";
for($i=-1;$i<=9;$i++)
echo chunk_split(strtoupper(bin2hex(gzdeflate($data,$i))),2," ") . PHP_EOL . PHP_EOL;
echo "\n\n\n";
for($i=-1;$i<=9;$i++)
echo chunk_split(strtoupper(bin2hex(gzencode($data,$i,FORCE_GZIP))),2," ") . PHP_EOL .
PHP_EOL;
echo "\n\n\n";
for($i=-1;$i<=9;$i++)
echo chunk_split(strtoupper(bin2hex(gzencode($data,$i,FORCE_DEFLATE))),2," ") . PHP_EOL
. PHP_EOL;
echo "\n\n\n";
Hope this helps. Please ThumbsUp if this saved you a lot of effort and time.
----
Server IP: 59.162.86.123
Probable Submitter: 122.173.190.24
----
Manual Page -- http://php.net/manual/en/function.gzdecode.php
Edit -- https://master.php.net/note/edit/112200
Del: integrated -- https://master.php.net/note/delete/112200/integrated
Del: useless -- https://master.php.net/note/delete/112200/useless
Del: bad code -- https://master.php.net/note/delete/112200/bad+code
Del: spam -- https://master.php.net/note/delete/112200/spam
Del: non-english -- https://master.php.net/note/delete/112200/non-english
Del: in docs -- https://master.php.net/note/delete/112200/in+docs
Del: other reasons-- https://master.php.net/note/delete/112200
Reject -- https://master.php.net/note/reject/112200
Search -- https://master.php.net/manage/user-notes.php