这篇文章主要介绍了PHP Post获取不到非表单数据的问题的解决办法以及代码分享,需要的朋友参考下。
问题描述
在使用vue-axios向后端post数据时,PHP端获取不到post的数据。
问题解决
修改php.ini配置
找到php.ini配置文件,查找enable_post_data_reading变量,修改为打开状态,注释掉句前分好
; Whether PHP will read the POST data.
; This option is enabled by default.
; Most likely, you won't want to disable this option globally. It causes $_POST
; and $_FILES to always be empty; the only way you will be able to read the
; POST data will be through the php://input stream wrapper. This can be useful
; to proxy requests or to process the POST data in a memory efficient fashion.
; http://php.net/enable-post-data-reading
enable_post_data_reading = On //大约656行,修改此条
修改配置后,发现还是不行,继续查阅资料。
获取非表单数据
搜集资料之后,发现vue-axios向后端post的是非表单数据(Ajax不同),在获取非表单数据时需要用php://input
$raw = file_get_contents('php://input');//获取非表单数据
echo $raw;//输出结果
PS:post时前端请求头要设置为
headers: {
"Content-type": "application/json; charset=utf-8"
}
沃梦达教程
本文标题为:PHP Post获取不到非表单数据的问题解决办法
基础教程推荐
猜你喜欢
- php实现数组筛选奇数和偶数示例 2024-02-05
- PHP实现文件下载【实例分享】 2024-04-27
- 设定php简写功能的方法 2023-03-17
- php实现构建排除当前元素的乘积数组方法 2022-11-23
- PHP+MySQL+sphinx+scws实现全文检索功能详解 2023-01-31
- PHP实现抽奖系统的示例代码 2023-06-26
- PHP判断一个字符串是否是回文字符串的方法 2024-01-31
- PHP手机短信验证码实现流程详解 2022-10-18
- php数组函数序列之array_sum() – 计算数组元素值之和 2024-01-15
- Yii框架连表查询操作示例 2023-02-13
