I am sending a Json array to server :
{
"Name":"Number",
"Name":"Number"
, ...
}
How can i receive it on PHP ?
Send method is POST .
Here is my android code :
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://192.168.1.7/admina/contacts_inout.php");
String json = "";
json = jsons.toString();
StringEntity se = new StringEntity(json);
httpPost.setEntity(se);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse httpResponse = httpclient.execute(httpPost);
isset($_POST['your_param_key']) or exit('param not found.');
$json = $_POST['your_param_key'];
$array = json_decode($json, true);
print_r($array);
Since PHP only handles POST-data which is application/x-www-form-urlencoded or multipart/form-data formatted, you'll have to use the RAW input
use
$sent_array = json_decode(file_get_contents('php://input'),true);
to get the data as an array
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.