PHP curl 发送post 表单请求
以下是 PHP curl 发送 post 表单请求的示例代码:
'example_user', 'password' => 'password123', 'email' => 'example_user@example.com' ); // 初始化 curl $ch = curl_init(); // 设置 curl 的选项 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 发送请求并获取响应 $response = curl_exec($ch); // 关闭 curl curl_close($ch); // 打印响应 echo $response; ?>在上面的示例中,我们首先设置了要请求的 URL 和要发送的数据。然后,我们使用 curl_init() 函数初始化 curl,并使用 curl_setopt() 函数设置 curl 的选项。最后,我们使用 curl_exec() 函数发送请求并获取响应,然后使用 curl_close() 函数关闭 curl。最后,我们打印响应。
原文地址: https://www.cveoy.top/t/topic/K00 著作权归作者所有。请勿转载和采集!