It's a problem with the http protocol. I work on the backend. Now I found a problem with the android programmer. He said that the data has been sent through POST request, but my php needs to use the json data type to receive the data, but I Many people I see on the Internet use $_POST[] to obtain data.
Questions
1. Do you really need php or json data type to receive data? So how to write the PHP code?
2. Is there a way for their Android Post request to send data to add a name? Just like our web site, it has a name.
Username username
Password userpass is an example. Please help. Thank you
php receives post data, usually $_POST can be used, if not, use file_get_contents("php://input");
The data he requested is in json format. It is very simple to process it with PHP. You only need to use json_decode() to parse it and it will become an array in PHP.
Variables such as username and password can be packaged in json.
1. It is recommended to use the following code
2. Must be able to add
Use $_POST for regular data, use file_get_contents('php://input') for XML and the like;
Don't use $GLOBALS["HTTP_RAW_POST_DATA"], it is obsolete in 7.0.
is equivalent to raw
This problem is easy to solve. First of all, there are two ways to pass the post request parameters:
form form submission
Submit in json format
The backend and the Android side just need to discuss a way to receive data. It is not as complicated as the author said
What framework does the author use? If you use laravel or lumen, directly connect Request::getContent(), and then json_decode(). If you want to implement it yourself, you can refer to laravel's implementation method: