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.
Oct 15, 2021
4
Level 3
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;
Please or to participate in this conversation.