1. file_get_contents("php://input")的作用:
(1)可以访问请求的原始数据的只读流
(2)POST 请求的情况下,
最好使用 php://input 来代替 $HTTP_RAW_POST_DATA,因为它不依赖于特定的 php.ini 指令
(3)php://input 可以读取http entity body中指定长度的值,由Content-Length指定长度,不管是POST方式或者GET方法提交过来的数据。但是,一般GET方法提交数据 时,http request entity body部分都为空。
(4)只有Coentent-Type为multipart/form-data的时候,PHP不会将http请求数据包中的相应数据填入php://input,否则其它情况都会
2. vue组件中axios使用post请求:
created() {
axios
.post("lognInByCode.php", {
account: "18171895497"
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
}
3. php中 file_get_contents("php://input")作用:
axios函数调用了该php接口文件,那么 file_get_contents("php://input")读取的就是post请求中的json数据:
所以:file_get_contents("php://input")的值为json数据:
"account" : "18171895497"
4. php 代码中:
$json_raw = file_get_contents("php://input"); //获取前端传来的json数据
$json_raw 就是前端传来的json数据
没错,就是这一行代码,就可以直接接受任何调用该php文件接口的前端所传来的json数据。