CURL请求中的GET方法是否等同于CURLOPT_POSTFIELDS? [英] Is there CURLOPT_POSTFIELDS equivalent for GET method in CURL request?
问题描述
我想要做的是使用GET方法执行带参数和值的CURL请求,但不希望在传递卷曲之前将它们混合,就像它在字符串中那样。
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
www.url-to-fetch.com/index.php?parameter=value
但我想传递单独的url字符串和查询字符串,或者最好的URL字符串+ CURL的参数和值的数组让我知道我想使用GET方法的CURL(CURLOPT_HTTPGET = TRUE)。
是否有与GET方法相同的CURLOPT_POSTFIELDS?
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?
推荐答案
使用函数 http_build_query()
从关联数组创建查询字符串。
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");
这篇关于CURL请求中的GET方法是否等同于CURLOPT_POSTFIELDS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!