[Turn] How to use file_get_contents("php://input")

$data = file_get_contents("php://input");
    php://input is a read-only stream with access to the requested raw data. In the case of POST requests, it is better to use php://input instead of $HTTP_RAW_POST_DATA because it does not depend on specific php.ini directives . Also, in this case $HTTP_RAW_POST_DATA is not populated by default, potentially requiring less memory than activating always_populate_raw_post_data. php://input is invalid when enctype="multipart/form-data". 
1, php://input can read the value of the specified length in the http entity body, and the length is specified by Content-Length, whether it is the data submitted by the POST method or the GET method. However, when the data is submitted by the general GET method, the http request entity body part is empty. 
2, php://input and $HTTP_RAW_POST_DATA read the same data, they only read data whose Content-Type is not multipart/form-data.
Study Note
 1, Coentent-Type will only fill in the global variable $_POST with the corresponding data in the http request packet when the value of Coentent-Type is application/x-www-data-urlencoded and multipart/form-data 
 2. When the Content-Type type is not recognized by PHP, it will fill the corresponding data in the http request packet into the variable $HTTP_RAW_POST_DATA 
 3,Only when the Coentent-Type is multipart/form-data, PHP will not fill in the corresponding data in the http request packet into php://input, otherwise it will. The length to be filled in, specified by Coentent-Length. 
 4. Only when the Content-Type is application/x-www-data-urlencoded, the php://input data is consistent with the $_POST data. 
 5. The php://input data is always the same as $HTTP_RAW_POST_DATA, but php://input is more efficient than $HTTP_RAW_POST_DATA, and does not require special settings in php.ini 
 6, PHP will fill in the query_path part of the PATH field into the global variable $_GET. Normally, the http request submitted by the GET method has an empty body.
Example
 1.php can receive xml data with file_get_contents("php://input") or $HTTP_RAW_POST_DATA

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324968946&siteId=291194637