在 PHP 中发送 GET 请求可以使用 cURL 库或者简单的 file_get_contents() 函数。下面是两种方法的示例:
使用 cURL 库发送 GET 请求:$url = 'http://example.com/api';$ch = curl_init($url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($ch);curl_close($ch);// 处理响应echo $response;使用 file_get_contents() 函数发送 GET 请求:$url = 'http://example.com/api';$response = file_get_contents($url);// 处理响应echo $response;以上代码示例中,$url 是要发送 GET 请求的 URL。通过 cURL 库或者 file_get_contents() 函数可以发送 GET 请求,并获取响应数据。接收到的响应数据可以进一步处理或者输出到页面上。


