php curl get request with parameters – Sending a GET request with a request body with PHP cURL

php curl get request with parameters Example. The most simple API call is the GET call you can use To make a GET request using Curl Example.

PHP Curl Get Request with Parameters Example

PHP cURL have set of curl function like curl_init(), curl_setopt(), curl_exec() etc. using cURL

PHP curl post request with parameters and get json response

index.php

 2];
  
    $info = http_build_query($params);
  
    $retriveWebUrl = $web_url."?".$info;
  
    curl_setopt($my_curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($my_curl, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($my_curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($my_curl, CURLOPT_URL, $retriveWebUrl);
    curl_setopt($my_curl, CURLOPT_TIMEOUT, 80);
       
    $response = curl_exec($my_curl);
        
    if(curl_error($my_curl)){
        echo 'Request Error:' . curl_error($my_curl);
    }else{
        echo $response;
    }
       
    curl_close($my_curl);
  
?>

PHP curl get request:


$my_curl = curl_init();
$data = http_build_query($dataArray);
$retriveWebUrl = $url."?".$data;
curl_setopt($my_curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($my_curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($my_curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($my_curl, CURLOPT_URL, $retriveWebUrl);
curl_setopt($my_curl, CURLOPT_TIMEOUT, 80);

$response = curl_exec($my_curl);

if(curl_error($my_curl)){
	echo 'Request Error:' . curl_error($my_curl);
}
else
{
	echo $response;
}

curl_close($my_curl);

cURL GET request example code

$url = "https://learnwebcode.github.io/json-example/animals-1.json";

//  Initiate curl
$my_curl = curl_init();
// Disable SSL verification
curl_setopt($my_curl, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($my_curl, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($my_curl, CURLOPT_URL,$url);
// Execute
$result=curl_exec($my_curl);
// Closing
curl_close($my_curl);

// Print the return data
print_r(json_decode($result, true));

Don’t Miss : PHP Curl POST And GET Methods

I hope you get an idea about php curl get request with parameters.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment