Please note the following PHP script first
PHP script A (http://127.0.0.1:8110/test.php):
1 $url= ' http://127.0.0.1:8110/demo.php ';2 //Curl Request3 $ch=curl_init ();4curl_setopt ($ch, Curlopt_url,$url);5curl_setopt ($ch, Curlopt_returntransfer,true);6curl_setopt ($ch, Curlopt_connecttimeout, 60);7curl_setopt ($ch, Curlopt_http_version,curl_http_version_1_1);8curl_setopt ($ch, Curlopt_post,true);9curl_setopt ($ch, Curlopt_postfields, ' A=dwadwafadwadwadwa&m=dwadwa ');Ten $result= Curl_exec ($ch); One Var_dump($result); A Exit();
PHP Script B (127.0.0.1:8110/demo.php):
1 Var_dump file_get_contents (' Php://input ')); 2 Var_dump $_post);
Execute the output of script a:
String (Bayi) "string" PHP input:a=dwadwafadwadwadwa&m=dwadwa "string (") "POST Data:array" "
Hey? Why is it so?
In fact, PHP, like other programming languages, has its own default input stream and output stream. In the Web environment, the input stream is the raw data of the post of the HTTP request, the output stream is the HTTP Body, in the CLI environment, is the current standard input and output stream (STDIN STDOUT). The $_post global array for PHP is parsed from the php://input.
Note 1: $HTTP _raw_post_data can also get the raw data for the POST of the HTTP request, but only when it encounters a MIME type that is recognized
Note that both 2:php://input and $http_raw_post_data cannot get the data under the Enctype= ' multipart/form-data ' form submission
Then get to the point where you can see that ThinkPHP3.1 's lib/core/dispatcher.class.php has the following code snippet (about 233 lines):
1 /**2 * Get the actual operation name3 * @access Private4 * @return String5 */6 Static Private functionGetaction ($var) {7 $action= !Empty($_post[$var]) ?8 $_post[$var] :9(!Empty($_get[$var])?$_get[$var]:c (' Default_action '));Ten unset($_post[$var],$_get[$var]);
In thinkphp, lib/core/dispatcher.class.php acts as a route-distribution feature (also known as a front-end controller), which resolves URLs and gives subsequent requests to the specified controller and action execution based on conventions and configurations.
Once we have used the conventions that rely on Php://input to read request data in development (such as some flash upload plugins, XML-RPC, internal interface services, etc.), and just commit the data (possibly binary data) is exactly understood as/&.+=.+/such a string, Causes thinkphp to have an inexplicable problem with URL distribution errors (failures) or incomplete data requests.
And this is because thinkphp in the distribution process, first check $_post re-check $_get, and check the acquisition and superfluous unset caused.
At this point, lib/core/dispatcher.class.php can be modified as follows:
1 /**2 * Get the actual operation name3 * @access Private4 * @return String5 */6 Static Private functionGetaction ($var) {7 //$action =!empty ($_post[$var])?8 //$_post[$var]:9 //(!empty ($_get[$var])? $_get[$var]:c (' default_action '));Ten //unset ($_post[$var],$_get[$var]); One A $action= (!Empty($_get[$var])?$_get[$var]:c (' Default_action ')); - unset($_get[$var]);
Problem is solved.
Summary: The problem is difficult to find, it is difficult to locate the cause, and it seems to only occur when the thinkphp is running in the ' Url_model ' + 0 mode.
Thinkphp3.1url Distributing bug fixes