使用PHP Android的Http Post响应为NULL

时间:2014-02-20 19:22:32

标签: android

这些json内容用于传递sync.php

{"details":[
{"Ticket_Date":"2014-02-11 13:09:10","Ticket_No":1,"Amount":1.2,"In_Out":"OUT","Vehicle_ID":1,"From_LocationID":1,"PriceType_ID":0,"Trip_ID":"876eb7c87d6ef156-207949831985","To_LocationID":3,"Inspector_Print ":1,"Driver_ID":1},
{"Ticket_Date":"2014-02-11 13:31:49","Ticket_No":2,"Amount":2,"In_Out":"OUT","Vehicle_ID":1,"From_LocationID":2,"PriceType_ID":0,"Trip_ID":"876eb7c87d6ef156-294637601577","To_LocationID":9,"Inspector_Print ":1,"Driver_ID":1}
]}

这是我的Android JAVA编码

 public void sendJson(final JSONObject json) {
        Thread t = new Thread() {
            public void run() {
                Looper.prepare(); //For Preparing Message Pool for the child Thread
                HttpClient client = new DefaultHttpClient();
                HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
                HttpResponse response;

                try {
                    HttpPost httpPost = new HttpPost("localhost/BusTicket/sync/sync.php");
                 // Prepare JSON to send by setting the entity
                    httpPost.setEntity(new StringEntity(json.toString(), "UTF-8"));

                    // Set up the header types needed to properly transfer JSON
                    httpPost.setHeader("Content-Type", "application/json");
                    httpPost.setHeader("Accept-Encoding", "application/json");
                    httpPost.setHeader("Accept-Language", "en-US");
                    response = client.execute(httpPost);

                    /*Checking response */
                    if(response!=null){ //RESPONSE IS NULL !!!!
                        InputStream in = response.getEntity().getContent(); //Get the data in the entity
                        Log.d(null,"Sync Reponse= "+ in.toString()); 
                    }

                } catch(Exception e) {
                    e.printStackTrace();
                }

                Looper.loop(); //Loop in the message queue
            }
        };
    }

这是我的sync.php代码

<?php
echo 'true'
?>

响应为空,为什么?我的JAVA有什么问题?

或有任何解决方案将json发布到php页面?

0 个答案:

没有答案