在PHP中发送GET请求,可以使用file_get_contents()函数或者cURL库来实现。以下是两种方法的示例代码:
file_get_contents()函数发送GET请求:$url = 'http://example.com/api/data?key1=value1&key2=value2';$response = file_get_contents($url);echo $response;使用cURL库发送GET请求:$url = 'http://example.com/api/data?key1=value1&key2=value2';$ch = curl_init($url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($ch);curl_close($ch);echo $response;以上代码示例中,$url是要发送GET请求的URL地址,可以在URL地址后面添加参数。file_get_contents()函数会直接返回请求的结果,而cURL库可以更加灵活地设置请求参数和处理请求的结果。


