Simulate post request:
'admin', 'user_pwd' => '123456' ); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); //发送 var_dump(curl_exec($curl)); //关闭 curl_close($curl);
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);
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');
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');
Processing response headers
CURLOPT_HEADER: Whether to obtain response header data
Get response header data:
curl_setopt($curl, CURLOPT_HEADER, true);
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');
Expires: Expiration date (GMT: Greenwich Mean Time)
gmdate() Format the timestamp to Greenwich mean time
self";
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!