Home  >  Article  >  Backend Development  >  Notes on Post upload of PHP study notes

Notes on Post upload of PHP study notes

不言
不言Original
2018-04-19 09:53:151631browse

The content of this article is about the precautions for Post upload of PHP study notes. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it

Today I originally wanted to use Postman Simulating POST to upload a set of Json data to the server, it turns out that the server cannot accept the uploaded data.

Server code:

<?php
	echo "<pre class="brush:php;toolbar:false">";
	var_dump($_POST);
	var_dump($_REQUEST);
	echo "
"; ?>

PostMan code:

POST /api.php/API/fish_woter_monitoring_add HTTP/1.1
Host: shrimp.cqjufy.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 356cd424-c710-2d33-ffa7-29157f939c56


{"SensorData": [{"equipment_ID": "20180418","PH_value": "7.28","oxygen_value": "5.03","temperature_value": "21.4"}]}

It turns out that the server never receives data.

Everyone after Baidu recommends using php://input to read

file_get_contents(&#39;php://input&#39;)

You can also use $GLOBALS['HTTP_RAW_POST_DATA'] to obtain POST native data, but the official recommendation is to use php ://input instead;

$GLOBALS[&#39;HTTP_RAW_POST_DATA&#39;]

The difference between the three:

$_POST 、$HTTP_RAW_POST_DATA、php://input三者之间的区别

HTTP_RAW_POST_DATA

1.Need to set the in php.ini always_populate_raw_post_data will only take effect if the value is On

2.Requires more memory than php://input

##php://input

cannot be used for enctype="multipart/ form-data"

#$_POST

1.Unable to parse content of non-application/x-www.form-urlencoded data types such as text/xml, application/json, etc.

##2.It has been verified that it cannot be used for enctype="text/plain"

3. When the Content-Type of the HTTP POST request is application/x-www-form -urlencoded or multipart/form-data, the variables will be passed into the current script in the form of an associative array.

related suggestion:

PHP software configuration for PHP learning

##php study notes object-oriented_php basics


The above is the detailed content of Notes on Post upload of PHP study notes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn