gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:15:21 25 4
gpt4 key购买 nike

我正在尝试将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com