我正在尝试使用通用库函数使用 curl 发送 GET 和 POST 请求。
function myCurl($url, $postData = null)
{
// Sets some default curl options here
$options = array(
...
CURLOPT_POSTFIELDS => $postData,
...
);
$ch = curl_init();
// this works and sends GET
// unset($options[CURLOPT_POSTFIELDS]);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
}
如果$postData设置,我希望此函数发送 POST ,否则将其视为GET. 然而,这是发送POST,甚至当我设置CURL_POSTFIELDS到null。取消设置CURL_POSTFIELDSoptions 数组元素有效并发送GET. 但是,有没有办法保留CURL_POSTFIELDScurl 选项并将其设置为默认的空值并使其发送GET请求?
慕的地8271018