在PHP中使用CURL对api执行推送调用
我不熟悉API调用 我需要在PHP中执行以下CURL调用:链接到API文档 我有以下更新的代码(但不工作):在PHP中使用CURL对api执行推送调用,php,html,ajax,api,curl,Php,Html,Ajax,Api,Curl,我不熟悉API调用 我需要在PHP中执行以下CURL调用:链接到API文档 我有以下更新的代码(但不工作): 您需要传递值CURLOPT\u POSTFIELDS $postData = array('value' => 10); curl_setopt($ch, CURLOPT_USERPWD, "APIKEY:0000000"); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); 同时将CURLOP
您需要传递值
CURLOPT\u POSTFIELDS
$postData = array('value' => 10);
curl_setopt($ch, CURLOPT_USERPWD, "APIKEY:0000000");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
同时将CURLOPT_POST
设置为true
curl_setopt($ch, CURLOPT_POST, true);
api需要一个将被忽略的密码。下面是工作代码
<?php
// encode the json object
$postData = json_encode(array('value' => 22));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://push.ducksboard.com/v/address');
curl_setopt($ch, CURLOPT_USERPWD, "0000000000000000000000:IGNORED");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_POST, true);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
尝试仍在工作,更新了帖子中的我的代码如果你可以看看为什么你有两个curl\u setopt($ch,CURLOPT\u POSTFIELDS,http\u build\u query($postData))代码>删除第一个
curl_setopt($ch, CURLOPT_POST, true);
<?php
// encode the json object
$postData = json_encode(array('value' => 22));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://push.ducksboard.com/v/address');
curl_setopt($ch, CURLOPT_USERPWD, "0000000000000000000000:IGNORED");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_POST, true);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>