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í)前端請求頭要設(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利用超級全局變量$_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)文章
約瑟夫環(huán)問題的PHP實(shí)現(xiàn) 使用PHP數(shù)組內(nèi)部指針操作函數(shù)
約瑟夫環(huán)問題相信大家都已經(jīng)很熟悉了,一直想使用 PHP 來實(shí)現(xiàn)一下,琢磨了老半天的時(shí)間終于弄出來了,也許沒有網(wǎng)上的一些代碼實(shí)現(xiàn)的簡潔高效,但是畢竟是寫出來了~呵呵。2010-10-10PHP備份數(shù)據(jù)庫生成SQL文件并下載的函數(shù)代碼
這是一個(gè)將指定數(shù)據(jù)庫里的所有表備份為一個(gè)SQL文件,可下載。這個(gè)源碼來自dedecms程序,功能挺多,也很實(shí)用,但是代碼的質(zhì)量還有待提高2012-02-02php數(shù)組函數(shù)array_walk用法示例
這篇文章主要介紹了php數(shù)組函數(shù)array_walk用法,分析了array_walk對數(shù)組中每個(gè)成員調(diào)用用戶函數(shù)的使用技巧,需要的朋友可以參考下2016-05-05php表設(shè)計(jì)實(shí)現(xiàn)短視頻評論區(qū)完整功能
這篇文章主要為大家介紹了php表設(shè)計(jì)實(shí)現(xiàn)短視頻評論區(qū)完整功能示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07