Is there CURLOPT_POSTFIELDS equivalent for GET method in CURL request?

邮差的信 提交于 2020-01-13 19:24:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!