PHP發送GET請求的方法有以下幾種:
$response = file_get_contents('http://example.com/api?param1=value1¶m2=value2');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api?param1=value1¶m2=value2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$client = new \http\Client;
$request = new \http\Client\Request('GET', 'http://example.com/api?param1=value1¶m2=value2');
$client->enqueue($request)->send();
$response = $client->getResponse()->getBody();
這些方法都可以用來發送GET請求,選擇哪種方法取決于個人的需求和偏好。