問題描述
在使用vue-axios向后端post數據時,PHP端獲取不到post的數據。
問題解決
修改php.ini配置
找到php.ini配置文件,查找enable_post_data_reading變量,修改為打開狀態(tài),注釋掉句前分好
; 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行,修改此條
修改配置后,發(fā)現(xiàn)還是不行,繼續(xù)查閱資料。
獲取非表單數據
搜集資料之后,發(fā)現(xiàn)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的CURL方法curl_setopt()函數案例介紹(抓取網頁,POST數據)
- PHP利用超級全局變量$_POST來接收表單數據的實例
- PHP之將POST數據轉化為字符串的實現(xiàn)代碼
- PHP CURL post數據報錯 failed creating formpost data
- php使用CURL模擬GET與POST向微信接口提交及獲取數據的方法
- 功能強大的PHP POST提交數據類
- PHP模擬post提交數據方法匯總
- 利用PHP fsockopen 模擬POST/GET傳送數據的方法
- php post大量數據時發(fā)現(xiàn)數據丟失問題解決方法
- 淺談PHP接收POST數據方式
- php使用socket post數據到其它web服務器的方法
- PHP中使用socket方式GET、POST數據實例
- php程序內部post數據的方法