Bonjour,
J'essaye d'envoyer des données au format Json sur un serveur Apache.
java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| //instantiates httpclient to make request
HttpClient httpclient = new DefaultHttpClient();
//url with the post data
HttpPost httpost = new HttpPost(strURL);
//passes the results to a string builder/entity
Log.d("output", json_valeurs.toString(2));
StringEntity se = new StringEntity("message=" + json_valeurs.toString());
//httpost.addHeader("content-type", "application/x-www-form-urlencoded");
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
httpost.setEntity(se);
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity(); |
php:
1 2 3 4
| print_r($_POST);
$json_string = $_POST['message'];
$json = json_decode($json_string);
print_r($json); |
J'ai comme retour un tableau vide => Array ( )
Par contre en remplacent
1 2
| httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json"); |
par
"httpost.addHeader("content-type", "application/x-www-form-urlencoded");"
j'ai une reponse du type
05-17 14:43:21.822: I/System.out(10151): [message] => {\"contact_pro\":[{\"adresse1\":\"3 ZA des Azures\",\"mailgeneral\":\"contact@richard.fr\",\"adresse2\":\"\",\"societe\":\"CHARPENTE Richard\",\"standard\":\"02.99.49.02.00\",\"ville \":\"LOUVIGNE-DE-BAIS\"},{\"adresse1\":\"\",\"mailgeneral\":\"\",\"adresse2\":\"\",\"societe\":\"JNL Services\",\"standard\":\"02.99.99.99.00\",\"ville \":\"\"},{\"adresse1\":\"ZA Ste CROIX\",\"mailgeneral\":\"\",\"adresse2\":\"\",\"societe\":\"Menuiserie Remy Pelerin\",\"standard\":\"02.99.37.38.50\",\"ville \":\"CHATEAUGIRON\"},{\"adresse1\":\"ZA Les Grands Sillons\",\"mailgeneral\":\"christophe.micault@wanadoo.fr\",\"adresse2\":\"\",\"societe\":\"SARL Christophe Micault\",\"standard\":\"02.99.44.03.92\",\"ville \":\"CORPS-NUDS\"},{\"adresse1\":\"La Fouaye\",\"mailgeneral\":\"contact@satel35.fr\",\"adresse2\":\"\",\"societe\":\"SATEL\",\"standard\":\"02.99.85.62.55\",\"ville \":\"Saint Gilles\"}]}
Je ne vois pas d'ou vient l'erreur !!!
Merci pour votre aide
cedric
Partager