java - 如何使 php 代码显示我发送到服务器的内容?

标签 java php android

我正在尝试将 jsonarray 上传到服务器,然后获取响应文本以查看服务器对对象执行的操作。在安卓端,我有这段代码:

            HttpPost httppost = new HttpPost("http://10.0.0.2/namedate.php");I am 
            HttpClient httpclient = new DefaultHttpClient();
            httppost.getParams().setParameter("jsonarray", json_a.toString());
            HttpResponse response = httpclient.execute(httppost);
            String responseText = EntityUtils.toString(response.getEntity());
            Log.d("ProviderTester", "The response text is "+ responseText);
            Log.i("JSONInfo","JSON object: " + json_a.toString());

jsonarray 从 logcat 看起来像这样:

04-10 21:29:53.293: I/JSONInfo(466): JSON object: ["[name=Mike, datetime=2012-04-10 21:29]","[name=Roger, datetime=2012-04-10 21:29]"]

目前我只是试图回显字符串,然后希望稍后从字符串中获取表格:

   <?php

    echo $_POST['jsonarray'];

   ?>

这是我从 logcat 得到的响应:

04-10 22:22:20.033: D/ProviderTester(499): The response text is 

我该如何解决这个问题,以便我可以看到我发送到服务器的 jsonarray 字符串?

编辑:当我将我的 Android 代码更改为:

            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("json_a", json_a.toString()));

            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            String responseText = EntityUtils.toString(response.getEntity());

然后我使用 php 脚本接受的答案在 LogCat 中得到以下响应:

04-10 23:05:39.833: D/ProviderTester(601): The response text is POST = array (
04-10 23:05:39.833: D/ProviderTester(601):   'json_a' => '[name=Mike, datetime=2012-04-10 21:29]\\",\\"[name=Roger, datetime=2012-03-10 21:29]\\"]\\"]',
04-10 23:05:39.833: D/ProviderTester(601): )
04-10 23:05:39.833: D/ProviderTester(601): GET = array (
04-10 23:05:39.833: D/ProviderTester(601): )
04-10 23:05:39.833: D/ProviderTester(601): request = array (
04-10 23:05:39.833: D/ProviderTester(601):   'Content-Length' => '174',
04-10 23:05:39.833: D/ProviderTester(601):   'Content-Type' => 'application/x-www-form-urlencoded',
04-10 23:05:39.833: D/ProviderTester(601):   'Host' => 'graasdfon.hostei.com',
04-10 23:05:39.833: D/ProviderTester(601):   'Connection' => 'Keep-Alive',
04-10 23:05:39.833: D/ProviderTester(601):   'User-Agent' => 'Apache-HttpClient/UNAVAILABLE (java 1.4)',
04-10 23:05:39.833: D/ProviderTester(601):   'Expect' => '100-Continue',
04-10 23:05:39.833: D/ProviderTester(601): )
04-10 23:05:39.833: D/ProviderTester(601): 
04-10 23:05:39.833: D/ProviderTester(601): <!-- www.000webhost.com Analytics Code -->

现在我只需要弄清楚如何处理 json_a 服务器端。感谢您的帮助!

最佳答案

我不知道是什么导致了您的问题(我不知道 Android/Java),但调试它的最佳方法是在 PHP 中简单地执行此操作:

<?php
    var_dump($_POST);
?>

这将使 PHP 输出它通过 POST 接收到的所有内容。

关于java - 如何使 php 代码显示我发送到服务器的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10109609/

相关文章:

php - 如何在搜索引擎中检索图像?

phpmailer:仅使用 "Reply To"地址回复

java - Android编辑文本属性

java - 同步方法的锁定行为

java - 如何自动将代码添加到我创建的每个类中

java.lang.NoClassDefFoundError : Could not initialize class org. apache.commons.text.StringEscapeUtils

java - 什么是java android开发的最佳IDE

java - 怎么听EditText?

javascript - 添加动态行后,我无法使用 php 发送数据

android - 如何确定 pulltorefreshlistview 的 onItemClick