[英]I am getting error while trying to get profile details from Fitbit using api. What is the reason?
[英]Error while using curl for doing a POST to a certain api. What is the bug in it?
<?php
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
curl_post('http://pastebin.com/api_public.php');
?>
我得到的錯誤是這個
Warning: http_build_query() [function.http-build-query]: Parameter 1 expected to be Array or Object. Incorrect value given in /opt/lampp/htdocs/pastebinapp/pasteb.php on line 20
Notice: name lookup timed out in /opt/lampp/htdocs/pastebinapp/pasteb.php on line 27
代碼中有錯誤嗎? 以及如何調試呢?
($options + $defaults) //doesn't preserve array keys
curl_post($url, array $post = null, array $options = array()) //$post needs to be array not null
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.