首頁  >  文章  >  後端開發  >  如何解決php取得不到form數據

如何解決php取得不到form數據

WJ
WJ原創
2020-06-10 17:05:334192瀏覽

如何解決php取得不到form數據

如何解決php取得不到form資料?

問題解決 修改php.ini配置

找到php.ini設定文件,尋找enable_post_data_reading變量,修改為開啟狀態,註解掉句前分好

; 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行,修改此条

修改配置後,發現還是不行,繼續查閱資料。

取得非表單資料

蒐集資料之後,發現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教學

以上是如何解決php取得不到form數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn