I’m trying to upload a jsonarray to a server and then get the response text to see what the server does to the object. On the android side, I have this code:
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());
The jsonarray looks like this from the 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]"]
At the moment I am just trying to echo the string and then hopefully later get the table out of the string:
<?php
echo $_POST['jsonarray'];
?>
Here are the responses I am getting from the logcat:
04-10 22:22:20.033: D/ProviderTester(499): The response text is
How do I fix this so I can see the jsonarray string that I am sending to the server?
EDIT: When I change my Android Code to:
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());
Then I get the following response in LogCat using the accepted answer for the php script:
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 -->
Now I just need to figure out how to process json_a server side. Thanks for the help!
PHP doesn’t have a way of doing an implicit toString() representation of a non-scalar data type. You’d need to do an explicit conversion.
e.g. If you want to see all the HTTP variables and the request headers, try something like:
(this won’t pick up on content written to STDIN but not encloded correctly as a POST)