简体   繁体   English

未记录的PHP自动将content-type:application / json解码为$ _REQUEST

[英]PHP undocumented automatically decode content-type:application/json to $_REQUEST

Is there really an undocumented feature in PHP to decode JSON POST body to $_REQUEST? PHP中确实有未记录的功能可将JSON POST正文解码为$ _REQUEST吗?

Not the same as PHP is automatically decoding JSON data? 不像PHP一样会自动解码JSON数据吗?

I am creating an API in PHP to receive parameters in FormData and JSON. 我正在PHP中创建一个API,以接收FormData和JSON中的参数。 When I test in POSTMAN, it appears that PHP automatically decodes POST body with content-type:application/json to $_REQUEST . 当我在POSTMAN中进行测试时,PHP似乎自动将content-type:application/json POST正文解码为$_REQUEST

I have been testing it whole afternoon and can't figure out how it is possible. 我整个下午都在测试它,不知道怎么可能。

This is the post request: 这是发帖请求:

curl -X POST \
  http://xxxxx.com/api/user/profile/update \
  -H 'content-type: application/json' \
  -d '{
    "id" : 174,
    "email" : "reed@xxxxx.com",
    "lang": "en_US",
}'

This is what I got in PHP 这就是我在PHP中得到的

var_dump($_REQUEST)

//output
  'id' => int 174
  'email' => string 'reed@xxxxx.com' (length=19)
  'lang' => string 'en_US' (length=5)

Am I seeing delusion ?? 我看到错觉了吗?

If I change POST content-type to anything which is not application/json , the automatic decoding does not happen. 如果我将POST内容类型更改为不是application/json任何内容,则不会发生自动解码。

I am using PHP5.6 + Phalcon 3.1. 我正在使用PHP5.6 + Phalcon 3.1。 Both not mentioning anything about automatically decoding JSON. 两者都未提及有关自动解码JSON的任何内容。

Here is my composer.json , I don't think any of these packages will do such a thing. 这是我的composer.json ,我认为这些软件包都不会做这样的事情。

"require": {
    "twilio/sdk" : "4.*",
    "crossjoin/browscap": "~2.0",
    "mixpanel/mixpanel-php" : "2.*",
    "guzzlehttp/guzzle": "^6.2",
    "geoip2/geoip2": "~2.0",
    "overtrue/wechat": "~3.1",
    "mongodb/mongodb": "^1.0.0",
    "symfony/var-dumper": "^3.1",
    "maxmind-db/reader": "~1.0",
    "pda/pheanstalk": "^3.1",
    "nesbot/carbon": "^1.21",
    "sendgrid/sendgrid": "~5.1",
    "ramsey/uuid": "^3.5",
    "phpmyadmin/motranslator": "^3.0"
}

Tried my best to search on google. 尽力在Google上进行搜索。 Can someone point me to a document with some explanation? 有人可以指出一些说明我吗?

I figured out. 我想通了。 It is PECL :: Package :: json_post 它是PECL ::包:: json_post

https://pecl.php.net/package/json_post https://pecl.php.net/package/json_post

This extension provides a PHP content type handler for "application/json" and "text/json" to PHP's form data parser. 该扩展为PHP的表单数据解析器提供了一个针对“ application / json”和“ text / json”的PHP内容类型处理程序。 If the Content-Type of an incoming request is text/json , the JSON contents of the request body will by parsed into $_POST . 如果传入请求的Content-Typetext/json ,则请求正文的JSON内容将解析为$_POST

I use remi repo to install PHP on centos. 我使用remi repo在centos上安装PHP。 It just comes with my installation of PHP 5.6 它随我的PHP 5.6安装一起提供

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM