A detailed description of the parameter submission and reception for the restful put method in PHP

Source: Internet
Author: User

We develop the RESTful interface of PHP will know there is put method update resources, that is how to use put this HTTP method to update resources, this article mainly share with you in PHP the RESTful put method parameter submission and receive detailed, hope to help everyone.

Send a PUT request

Sometimes we find that the parameter received by the Put method is not the type we want, we want a parameter array, but we receive a string, the problem is we put Content-Type the type wrong, we send application/json or the application/x-www-form-urlencoded corresponding data, but it Content-Type is multipart/form-data , The data that is received becomes form-data:

----------------------------217287928126218120101488content-disposition:form-data; Name= "status" 1----------------------------217287928126218120101488--

and restful data is basically transmitted in JSON format, so the HTTP headers sent should be Content-Type=application/json .
Using Post man:

Receive put request parameters

The Put method accepts parameters using:

Parse_str (file_get_contents (' Php://input '), $data);

The parameters are saved in $data .
If you use the TP5 framework, you can use helper functions to implement:

Input (' put.status '); input (' Put. ');

PS: Here form-data misunderstanding should be caused by the PHP post and put method internal parsing multipart/form-data data, the Post method to parse the parameters to $_post and the content contents empty, and put does not have this step, so pay attention to the use of the difference.

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.