PHP Development: The rest interface post method gets the object submitted by the client

Source: Internet
Author: User
The Post method is used to add data according to the rest specification. If you submit the object in the form of a traditional application/x-www-form-urlencoded form, you need to take out the value of each field, put it in the parameter, and then restore it to the corresponding object for processing after it is received by the server. This is additional work for both the client and the server.

The best way to transfer objects between the client and the server is to use JSON or XML, and the client and the server have the tools to serialize or deserialize the object. Individuals are more inclined to JSON, the code is more concise, the conversion is more convenient.

When the client submits the request, it sets Content-type to "Application/json;charset=utf-8″, tells the server that the message body is JSON, and the server determines $_server[' Content_Type '], if it is JSON, The message body is obtained using file_get_contents (' Php://input '), which is the JSON string after the object is serialized and then processed accordingly.

©2016, frozen fish. Please respect the author's labor results, copy reprint reservation site link! Application Development notes

  • 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.