PHP Post获取不到非表单数据的问题解决办法

yipeiwu_com6年前PHP代码库

问题描述

在使用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 在线打包_支持子目录

程序使用了php的zip扩展,如果服务器支持,那就可以用了^_^,生成的zip压缩包可以用winrar等来解压的,当然也可以用php来解压。解压的过段时间再发布了。<?php&nb...

理解php原理的opcodes(操作码)

Opcondes是一种php脚本编译后的中间语言,就像Java的Byte Code,或者.NET 的MSL 。(都没了解过~)   举个文中的例子 复制代码 代码如下: <?php...

PHP编程实现脚本异步执行的方法

本文实例讲述了PHP编程实现脚本异步执行的方法。分享给大家供大家参考,具体如下: php语言得用fsockopen()函数,实现脚本异步运行,代码如下 异步请求函数(用debug参数若为...

必须收藏的23个php实用代码片段

在编写代码的时候有个神奇的工具总是好的!下面这里收集了 40+ PHP 代码片段,可以帮助你开发 PHP 项目。 这些 PHP 片段对于 PHP 初学者也非常有帮助,非常容易学习,让我...

php集成环境xampp中apache无法启动问题解决方案

php集成环境xampp中apache无法启动问题解决方案

排查原因,发现是80端口被其它程序占用(很常见的事情╮(╯_╰)╭)。 解决方法 用记事本打开目录x:\xampp\apache\conf下的http.conf文件,将Listen:8...