更新时间:2023-02-26 14:06:42
后端可以像浏览器一样做POST。
A backend can do a POST just like the browser. Much of the internet is server-to-server communication in this manner.
以下是PHP中的一个示例POST请求(使用Curl)
Here's an example POST request in PHP (using Curl)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/site.html");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
curl_close ($ch);
另一种设置POST参数而不是手动创建param字符串的方法:
An alternative way to set the POST parameters instead of manually creating the param string:
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(array('postvar1' => 'value1')));