日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php post请求后端拿不到值_PHP Post获取不到非表单数据的问题解决办法

發布時間:2023/12/1 php 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php post请求后端拿不到值_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 Post获取不到非表单数据的问题解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。