簡體   English   中英

PHP-接收Json(POST)

[英]PHP - Receive Json (POST)

我正在將Json數組發送到服務器:

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

我如何在PHP上接收它?

發送方法是POST。

這是我的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);

由於PHP僅處理應用程序/ x-www-form-urlencoded或multipart / form-data格式的POST數據,因此您必須使用RAW輸入

采用

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

以數組形式獲取數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM