Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET request with data-urlencode in PHP

I am trying to make an API call to Influx db from PHP program. The curl request to be made is -

curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "q=SHOW MEASUREMENTS"

The code in PHP that I am stuck with is -

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "http://localhost:8086/query?pretty=true",
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache"
    ),
));

I am not sure in which curl_setopt_array should I send the q=SHOW MEASUREMENTS

like image 453
pradyotghate Avatar asked Dec 05 '16 15:12

pradyotghate


1 Answers

$query = urlencode("SHOW MEASUREMENTS");

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "http://localhost:8086/query?pretty=true&q=" . $query,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache"
    ),
));
like image 60
pradyotghate Avatar answered Sep 30 '22 02:09

pradyotghate