5

What I want to do is to perform CURL request with parameters and values by using GET method but don't want to mix them before passing to curl like it is in the string

www.url-to-fetch.com/index.php?parameter=value

but I would like to pass separate url string and query string or at best url string + an array of parameters and values to CURL with letting to know CURL that I want to use GET method (CURLOPT_HTTPGET=TRUE).
is there any CURLOPT_POSTFIELDS equivalent for GET method?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Jimmix
  • 4,744
  • 2
  • 25
  • 56

1 Answers1

6

Use the function http_build_query() to create the query string from an associative array.

$query = http_build_query($params);
curl_setopt($ch, CURLOPT_URL, "www.url-to-fetch.com/index.php?$query");
Barmar
  • 669,327
  • 51
  • 454
  • 560
  • so there is no field option method like in POST method isn't it? just to separate url and parameters with their values? it makes a bit mess in debugging that joining www.url-to-fetch.com/index.php?$query because then it leads to www.url-to-fetch.com/index.php?parameter=value but the actual url is www.url-to-fetch.com/index.php and second (different) thing are all parameters and their values. – Jimmix May 06 '13 at 18:00
  • 1
    The whole difference between `GET` and `POST` is that `GET` puts the parameters in the URL, `POST` puts it in the data. – Barmar May 06 '13 at 18:07
  • I hoped that maybe curl could manage that in different way and build www.url-to-fetch.com/index.php?parameter=value just before requesting page and give an access to url and parameters as separate fields but if not then i will manage that on my own. thanks for clarification, – Jimmix May 06 '13 at 18:18