2

我是 API 调用的新手

我需要在 PHP 中执行以下 CURL 调用:链接到 API 文档http://dev.ducksboard.com/apidoc/tutorial/#overview

curl -v -u APIKEY:x -d '{"value": 10}' https://push.ducksboard.com/values/235

我有以下更新的代码(但不工作):

 <?php


$postData = array('value' => 10);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://push.ducksboard.com/v/*****');
curl_setopt($ch, CURLOPT_USERPWD, "000000000000000");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
 curl_setopt($ch, CURLOPT_POST, true); 

  $result=curl_exec ($ch);
  curl_close ($ch);
  echo $result;
?>
4

2 回答 2

1

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;
?>
于 2013-07-09T06:27:12.967 回答
1

你需要传递值CURLOPT_POSTFIELDS

$postData = array('value' => 10);
curl_setopt($ch, CURLOPT_USERPWD, "APIKEY:0000000");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); 

也设置CURLOPT_POSTtrue

curl_setopt($ch, CURLOPT_POST, true); 
于 2013-07-08T13:51:58.497 回答