The method of receiving post pass values php

This time in the study php interface, the use of analog jmeter send data to the server php, php how to look past the reception data transmission post, encountered a few problems, after some degree of your mother finally be understood, record it:

 

Here recorded two common ways post

The first:

content-type is application / x-www-form-urlencoded, which is a post default data format, using jquery ajax to post data when the default is this way, the data format in this way the transmission is: username = admin & password = 123456. (Recommended Learning: PHP Programming from entry to the master)

When the server receives the most common is to use $ _POST manner, using the acquired username $ _POST [ 'username'] to obtain normal.

The second:

In this way studied quite a while to discover how to receive and process the data therein, content-type is application / json, is not directly on the application / json data format received a $ _POST way in php. application / json formatted data types:

1

2

3

4

{

"username":"admin",

"password":"123455"

}

For this type of post the data to the server, (post past data transmission mode) receives native data type, and then use analytic json_encode before it can operate: in php need 'INPUT php //' , php code:

1

2

3

$raw_post_data = file_get_contents('php://input');

$arr = json_decode($raw_post_data,true);

echo $arr['username'];

At this point, we can obtain the application / x-www-form-urlencoded format data, the format of the acquired application / json data by $ _POST [ 'username'].

 

"Huizhou marble platform." Detection accuracy of Huizhou marble platform face what?

Guess you like

Origin www.cnblogs.com/furuihua/p/11491651.html