我正在使用cURL进行API调用,下面是我的代码:
$data = array(
'r' => 'create',
'_object' => 'Question',
'_api_key' => '........',
'_user_id' => $creator_id,
'_subtype_id' => $type_id,
'_subtopic_id' => $subtopic_id,
'_title' => $title,
'_description' => $description,
'_encoded_xml' => $main_xml
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://urlhere/v1/resources/objects");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
print_r($server_output);
字符串
我希望这些参数将作为GET
而不是POST
请求发送,我怎么能做到这一点,请咨询
1条答案
按热度按时间ifmq2ha21#
CURLOPT_POSTFIELDS
用于POST
请求的主体(有效负载)。对于GET
请求,有效负载是URL的一部分。您只需要使用需要发送的参数(如果有的话)构造URL,并删除cURL的其他选项。
字符串