Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Android GZIPInputStream无法识别gzip格式_Php_Android_Gzip - Fatal编程技术网

Php Android GZIPInputStream无法识别gzip格式

Php Android GZIPInputStream无法识别gzip格式,php,android,gzip,Php,Android,Gzip,这真的让我很恼火,在这里找到问题对我来说非常重要。 下面的android代码没有为我解压 HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("http://www**************/get.php"); get.addHeader("Accept-Encoding", "gzip"); try {

这真的让我很恼火,在这里找到问题对我来说非常重要。 下面的android代码没有为我解压

HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet("http://www**************/get.php");
        get.addHeader("Accept-Encoding", "gzip");
        try {                   
            HttpResponse response = client.execute(get);
            InputStream instream = response.getEntity().getContent();
            Header contentEncoding = response.getFirstHeader("Content-Encoding");
            //Log msg header
            Header[] header = response.getAllHeaders();
            for(Header i : header) {
                Log.d("TEST", i.getName() + ":" + i.getValue() );
            }
            if (contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                Log.d("TEST", "Content is gzipped");
                try {
                    instream = new GZIPInputStream(instream);
                    processStream(instream);
                 } finally {
                     instream.close();
                 }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
Logcat输出:

D/TEST    ( 1067): Date:Fri, 03 Jun 2011 05:18:33 GMT
D/TEST    ( 1067): Server:Apache
D/TEST    ( 1067): X-Powered-By:PHP/5.2.10
D/TEST    ( 1067): Content-Encoding:gzip
D/TEST    ( 1067): Content-Length:765
D/TEST    ( 1067): Connection:close
D/TEST    ( 1067): Content-Type:application/json
D/TEST    ( 1067): Content is gzipped

W/System.err( 1067): java.io.IOException: Unknown format
W/System.err( 1067):    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:85)
W/System.err( 1067):    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:66)
W/System.err( 1067):    at com.mannotron.gallery.GalleryExample$GetImages.doInBackground(GalleryExample.java:69)
W/System.err( 1067):    at com.mannotron.gallery.GalleryExample$GetImages.doInBackground(GalleryExample.java:1)
W/System.err( 1067):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
W/System.err( 1067):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err( 1067):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err( 1067):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
W/System.err( 1067):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
W/System.err( 1067):    at java.lang.Thread.run(Thread.java:1096)
?>


我在php的服务器端使用gzip尝试了gz_encode()和outputbuffering。有人能看出我做错了什么吗?谢谢您的时间。

流看起来不对,因为它应该以“1f8b”开头。原因可能是您的php文件中出现了错误的“a”。但是发布的示例似乎没有问题。

您能在客户端显示流内的前几个字节吗?流以[a,1f,8b,8,0,0,0,0,0,3,bd,96,…]的形式出现,这是您的意思吗?BufferedReader中的字符集如下所示:D/TEST(1275):▼´┐└Ç└Ç└Ç└Ç└Ç└Ç♥´┐¢´┐¢´┐■n´┐¢0►´┐■_e´┐¢´┐¢´┐■I´┐¢8!´┐¢Ë╗¶´┐是的。第一个“a”是错误的。gzip文件/流应以“1f8b”开头。你是否碰巧在你的php文件中有一个游离的“a”?ascii中的hmmm a似乎是一个新行,你现在知道它是如何进入的吗?php正是我所提出的(只有
//ob_start('ob_gzhandler');
header("HTTP/1.1 200 OK");
header("Content-Type: application/json"); 
header("Content-Encoding: gzip"); 


$dbhost = "xxxxxx";
$dbname = "xxxxxx";
$user = "xxxxxx";
$pass = "xxxxxx";

//Open databse connection
$db = new mysqli($dbhost,$user,$pass,$dbname) or die('Error opening db');   


$query = "SELECT * FROM Spots; ";
$result = null;
$result = $db->query($query);
$data = array();
while($row = $result->fetch_assoc()) {
    $data [] = $row;
}
$spots = '{"spots":'.json_encode($data)."}";
echo gzencode($spots,FORCE_GZIP);

$db->close();   
//ob_flush();