1 回答

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊
這個(gè)答案可能有點(diǎn)晚了,但為了其他遇到同樣問題的人:
問題原來是Content-Type標(biāo)題有 value application/json。當(dāng) PHP 解析數(shù)據(jù)以放入$_POST超級(jí)全局時(shí),它期望此標(biāo)頭具有值application/x-www-form-urlencodedor multipart/form-data,即 Web 標(biāo)準(zhǔn)內(nèi)容類型。接收application/json內(nèi)容類型數(shù)據(jù)時(shí),您必須從php://input流中訪問它。
解決方案最終看起來像這樣:
$json_string_data = file_get_contents('php://input');
$decoded_data = json_decode($json_string_data, true);
如果您的應(yīng)用程序希望數(shù)據(jù)在$_POST超級(jí)全局中可用,那么可以使用以下(無可否認(rèn)的 hacky)解決方案:
$json_string_data = file_get_contents('php://input');
$decoded_data = json_decode($json_string_data, true);
$_POST = $decoded_data;
或者,為簡(jiǎn)潔起見:
$_POST = json_decode(file_get_contents('php://input'), true);
- 1 回答
- 0 關(guān)注
- 337 瀏覽
添加回答
舉報(bào)