2018-06-14 13:36:05 1408瀏覽
本篇文章扣丁學(xué)堂PHP培訓(xùn)小編主要是和大家分享一下Post獲取不到非表單數(shù)據(jù)怎么辦,文章中會(huì)列出具體的代碼供大家參考,對(duì)此感興趣的小伙伴就隨小編一起來(lái)看一下吧。
問(wèn)題描述:
在使用vue-axios向后端post數(shù)據(jù)時(shí),PHP端獲取不到post的數(shù)據(jù)。
問(wèn)題解決:
修改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" }
關(guān)于PHP Post獲取不到非表單數(shù)據(jù)的問(wèn)題解決辦法扣丁學(xué)堂PHP在線學(xué)習(xí)小編就先給大家介紹這些,希望對(duì)小伙伴們有所幫助,想要了解更多內(nèi)容的小伙伴可以登錄扣丁學(xué)堂官網(wǎng)咨詢??鄱W(xué)堂是專業(yè)的PHP培訓(xùn)機(jī)構(gòu),不僅有專業(yè)的老師和與時(shí)俱進(jìn)的課程體系,還有大量的PHP在線視頻供學(xué)員觀看學(xué)習(xí)哦??鄱W(xué)堂PHP技術(shù)交流群:374332265。
【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“php培訓(xùn)資訊”的相關(guān)文章>>