问题
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?
回答1:
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");
来源:https://stackoverflow.com/questions/16404162/is-there-curlopt-postfields-equivalent-for-get-method-in-curl-request