Detailed explanation of parameter submission and reception of Restful PUT method in PHP

小云云
Release: 2023-03-22 10:14:01
Original
6268 people have browsed it

We who develop the Restful interface of PHP will all know that there is a PUT method to update resources, so how to use the PUT HTTP method to update resources? This article mainly shares with you the detailed explanation of parameter submission and reception of the Restful PUT method in PHP. I hope it can help everyone. .

Send PUT request

Sometimes we find that the parameters sent by the PUT method are not of the type we want. We want a parameter array, but it is received as a string. This kind of The problem is actually that we got the type of Content-Type wrong. What we sent was application/json or application/x-www-form-urlencoded corresponding to data, but Content-Type is multipart/form-data, so the received data becomes form-data:

----------------------------217287928126218120101488Content-Disposition: form-data; name="status"

1
----------------------------217287928126218120101488--
Copy after login

and Restful The data is basically transmitted in json format, so the HTTP header sent should be Content-Type=application/json.
Use POST MAN:
Detailed explanation of parameter submission and reception of Restful PUT method in PHP
Detailed explanation of parameter submission and reception of Restful PUT method in PHP

Receive PUT request parameters

PUT method accepts parameters use:

parse_str(file_get_contents('php://input'), $data);
Copy after login

Parameter saving In $data.
If you use the tp5 framework, you can use the helper function:

input('put.status');input('put.');
Copy after login

ps: The form-data misunderstanding here should be parsed internally by PHP's POST and PUT methods multipart/form-data Due to the different data methods, the POST method parses the parameters into $_POST and leaves the content blank, while PUT does not do this step, so pay attention to the difference in usage.

Related recommendations:

PHP’s automatic identification of the content type returned by Restful

The above is the detailed content of Detailed explanation of parameter submission and reception of Restful PUT method in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!