How does the php server respond to post requests?

Release: 2023-02-27 15:44:01
Original
5405 people have browsed it

How does the php server respond to post requests?

Simulate post request:

 'admin', 'user_pwd' => '123456' ); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); //发送 var_dump(curl_exec($curl)); //关闭 curl_close($curl);
Copy after login

php responds to post request:

CURLOPT_RETURNTRANSFER: Whether to output the response directly or process it in the form of a return value
Process the response data in the form of a return value:

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
Copy after login

POST file upload

Post data uses the file address, use the @ sign before the file instead of the string

$post_data = array('image' => '@c:/1.jpg');
Copy after login

Handle session COOKIE

CURLOPT_COOKIEFILE: Whether to send cookies

CURLOPT_COOKIEJAR: Specify the storage location of cookie variables set by the storage server

curl_setopt($curl, CURLOPT_COOKIEFILE, true); curl_setopt($curl, CURLOPT_HEADER, 'c:/cookie.txt');
Copy after login

Processing response headers

CURLOPT_HEADER: Whether to obtain response header data

Get response header data:

curl_setopt($curl, CURLOPT_HEADER, true);
Copy after login

Operation response

Operation response header:

header() function

json:header("Content-type: application/json");
(ie6:header("Content-type: text/json");) picture :header('Content-Type:image/jpeg');, header('Content-Type:image/png'); etc.; encoding: header("Content-type:text/html;Charset=utf-8") ;

Operation response body

Any output is the response body. (echo, print, var_dump, all HTML code outside PHP tags)

Control browser cache

header('Expires: ' . gmdate('D, d M Y H:i:s', time()+5) . ' GMT');
Copy after login

Expires: Expiration date (GMT: Greenwich Mean Time)

gmdate() Format the timestamp to Greenwich mean time

         self";
Copy after login

Recommended reading:php server

The above is the detailed content of How does the php server respond to post requests?. 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
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!