小程序官方介绍

当小程序向PHP接口传递数据时,PHP接收参数常用这三个方法.
$_GET
$_POST
file_get_contents('php://input')
但是由于前端传递数据的方式不同,后台可能接受不到,下边是服务器端PHP脚本,分别用三种方式接收参数并返回接收到的数据.
<?php
# "小程序测试";
echo '用$_GET接收'."\n";
print_r($_GET);
echo '用$_PSOT接收'."\n";
print_r($_POST);
echo '用file_get_contents(\'php:input\')接收'."\n";
echo file_get_contents('php://input');
然后在小程序中输出结果
小程序GET请求

小程序POST请求,header:{'content-type': 'application/json'}

小程序POST请求,header:{'content-type': application/x-www-form-urlencoded'}

网友评论