About PHP Development HTTP Server workaround

Source: Internet
Author: User
Tags http post php server
About PHP Development HTTP Server
Recently due to work needs, to a mobile phone game to get a management game leaderboard server, after the classmate introduced, think that using PHP to develop relatively simple, so temporarily to learn the basic syntax of PHP and online search a lot of information on how to develop the server.
I am here to talk about my own server process encountered problems, I hope that the same as I need to develop a new PHP server novice can get help, as for the master, you ignore me.
Many of the information on the Internet is about how PHP simulates sending HTTP requests, there is little information on how the server obtains client requests, perhaps through the system learning to know, but for my temporary learning, is really a mishap.
After I find the data PHP server to accept the client's data can be obtained through the $_post,$_get,$_request. The client needs to use the corresponding $_post,$_get to submit the data, and $_request seems to be able to.
As for the difference between $_post,$_get, Baidu too much you can find your own
$_post,$_get return is the parameters that your client passed, you can handle these parameters to complete the function, as you want to return data to the client, only need to echo on the line
If the client uses Get method to send the request, want to get the data is very simple, only need to use $_server[' query_string ' to get, information from http://hi.baidu.com/iigyphfsjfgjkye/item/ F180B2FBC5AA18EE1B111FC1 More information check it out for yourself.

I do this time the PHP server, do not know what the reason, with $_post,$_get,$_request can not get to the data. So I looked for $globals[$HTTP _raw_post_data] and file_get_contents ("Http://input") to get the data
The above two methods can get the client post to the request the first heard that it seems unable to accept a data, forget
I used the second $request = file_get_contents ("Http://input") and got the parameters of the client post.

Introduce a software fidder here, Baidu can download. This software can be used instead of the client to send requests such as get,post and so on, can test whether your server can receive the client's request.

------Solution--------------------
The data cannot be obtained with $_post,$_get,$_request. So I looked for $globals[$HTTP _raw_post_data] and file_get_contents ("Http://input") to get the data.

is your data binary stream?

$_post: An array of variables passed by the HTTP POST method. is an automatic global variable.
$GLOBALS [' Http_raw_post_data ']: always produces $HTTP _raw_post_data variable contains the original POST data. This variable is only generated when it encounters data that does not recognize the MIME type. $HTTP _raw_post_data is not available for enctype= ' multipart/form-data ' form data.
That is to say, basically $globals[' http_raw_post_data ' is the same as $_post.

However, if the POST data is not recognized by PHP, you can use $GLOBALS [' Http_raw_post_data '] to receive, such as text/xml or soap and so on.

Additional notes: PHP Default recognized data type is the application/x-www.form-urlencoded standard data type

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.