Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Spiral's avatar

How can send params array in curl get request

I have an array of params which I'm sending in CURL get request but not getting params which I have checked. I want to send these params(key, value) in curl get request but not sending giving empty data

this is my code you can see that

$params = [];

foreach($product_data->params as $param) {

    array_push($params, $param);
}

$curl = curl_init($product_data_url);

$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $token,
];

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_URL, $product_datat_url);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");   
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


$resp = curl_exec($curl);
if($resp === false)
{
    echo "Error Number:".curl_errno($curl)."<br>";
    echo "Error String:".curl_error($curl);
}
curl_close($curl);

return $resp;
0 likes
4 replies
bugsysha's avatar

Are you using Laravel? If so then you can use the HTTP client that comes with it. It will make things more readable and easier to understand. Consider pulling in the Guzzle library.

1 like
Spiral's avatar

@bugsysha Yes, I'm using laravel . Can you give me an example of that how can use that like that

bugsysha's avatar

@Spiral point of Laravel is to be more on the OOP side when you write the code. Maybe you can benefit from some series like Laravel from scratch here on Laracasts.

1 like

Please or to participate in this conversation.