简体   繁体   English

PHP-接收Json(POST)

[英]PHP - Receive Json (POST)

I am sending a Json array to server : 我正在将Json数组发送到服务器:

{
"Name":"Number",
"Name":"Number" 
, ...
}

How can i receive it on PHP ? 我如何在PHP上接收它?

Send method is POST . 发送方法是POST。

Here is my android code : 这是我的android代码:

        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 由于PHP仅处理应用程序/ x-www-form-urlencoded或multipart / form-data格式的POST数据,因此您必须使用RAW输入

use 采用

$sent_array = json_decode(file_get_contents('php://input'),true);

to get the data as an array 以数组形式获取数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM