問(wèn)題描述
在使用vue-axios向后端post數(shù)據(jù)時(shí),PHP端獲取不到post的數(shù)據(jù)。
問(wèn)題解決
修改php.ini配置
找到php.ini配置文件,查找enable_post_data_reading變量,修改為打開(kāi)狀態(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)頁(yè),POST數(shù)據(jù))
- PHP利用超級(jí)全局變量$_POST來(lái)接收表單數(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ù)丟失問(wèn)題解決方法
- 淺談PHP接收POST數(shù)據(jù)方式
- php使用socket post數(shù)據(jù)到其它web服務(wù)器的方法
- PHP中使用socket方式GET、POST數(shù)據(jù)實(shí)例
- php程序內(nèi)部post數(shù)據(jù)的方法