Devo creare una pagina php, index_test.php, che riceva dei dati in formato json da una posta (la post è fatta in java), non riesco a capire come fare a ricevere i dati in php, questo è quello che penso vada scritto
cosa devo scrivere al posto dei punti interrogativi?Codice PHP:
<?php
$json = $_POST[??????];
$data = json_decode($json, TRUE); ?>
questa è la chiamata, in java, che mandata i dati (email e password)
[JAVA]
private String SendDataFromAndroidDevice() {
String result = "";
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("mail", mEmail);
jsonObject.put("password", mPassword);
String url = "http://www.miosito.it/index_test.php";
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(url);
// 4. convert JSONObject to JSON to String
String json = jsonObject.toString();
// 5. set json to StringEntity
StringEntity se = new StringEntity(json);
// 6. set httpPost Entity
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
// 9. receive response as inputStream
InputStream inputStream = httpResponse.getEntity().getContent();
// 10. convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
[/JAVA]