PHP Post獲取不到非表單數(shù)據(jù)的問題解決辦法
問題描述
在使用vue-axios向后端post數(shù)據(jù)時(shí),PHP端獲取不到post的數(shù)據(jù)。
問題解決
修改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ù)查閱資料。
獲取非表單數(shù)據(jù)
搜集資料之后,發(fā)現(xiàn)vue-axios向后端post的是非表單數(shù)據(jù)(Ajax不同),在獲取非表單數(shù)據(jù)時(shí)需要用php://input
$raw = file_get_contents('php://input');//獲取非表單數(shù)據(jù)
echo $raw;//輸出結(jié)果
PS:post時(shí)前端請(qǐng)求頭要設(shè)置為
headers: {
"Content-type": "application/json; charset=utf-8"
}
- php獲取POST數(shù)據(jù)的三種方法實(shí)例詳解
- PHP的CURL方法curl_setopt()函數(shù)案例介紹(抓取網(wǎng)頁,POST數(shù)據(jù))
- PHP利用超級(jí)全局變量$_POST來接收表單數(shù)據(jù)的實(shí)例
- PHP之將POST數(shù)據(jù)轉(zhuǎn)化為字符串的實(shí)現(xiàn)代碼
- PHP CURL post數(shù)據(jù)報(bào)錯(cuò) failed creating formpost data
- php使用CURL模擬GET與POST向微信接口提交及獲取數(shù)據(jù)的方法
- 功能強(qiáng)大的PHP POST提交數(shù)據(jù)類
- PHP模擬post提交數(shù)據(jù)方法匯總
- 利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法
- php post大量數(shù)據(jù)時(shí)發(fā)現(xiàn)數(shù)據(jù)丟失問題解決方法
- 淺談PHP接收POST數(shù)據(jù)方式
- php使用socket post數(shù)據(jù)到其它web服務(wù)器的方法
- PHP中使用socket方式GET、POST數(shù)據(jù)實(shí)例
- php程序內(nèi)部post數(shù)據(jù)的方法
相關(guān)文章
淺談PHP中類和對(duì)象的相關(guān)函數(shù)
下面小編就為大家?guī)硪黄獪\談PHP中類和對(duì)象的相關(guān)函數(shù)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04
php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實(shí)現(xiàn)代碼
php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-07-07
PHP中通過HTTP_USER_AGENT判斷是否為手機(jī)移動(dòng)終端的函數(shù)代碼
經(jīng)常我們需要做一些判斷是否是手機(jī)訪問的時(shí)候,然后進(jìn)行自動(dòng)跳轉(zhuǎn)操作,這是從一個(gè)PHP框架分離出來的一段判斷是否為手機(jī)移動(dòng)終端的函數(shù),分享下2013-02-02
PHP簡(jiǎn)單操作MongoDB的方法(安裝及增刪改查)
這篇文章主要介紹了PHP簡(jiǎn)單操作MongoDB的方法,簡(jiǎn)單分析了php安裝及操作MongoDB數(shù)據(jù)庫(kù)的方法,涉及PHP針對(duì)MongoDB數(shù)據(jù)庫(kù)基本的增刪改查等操作技巧,需要的朋友可以參考下2016-05-05

