[英]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.