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');
?>开发者_运维问答;
The error I am getting is this
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
is there an error in the code ? and how to debug it ?
($options + $defaults) //doesn't preserve array keys
curl_post($url, array $post = null, array $options = array()) //$post needs to be array not null
精彩评论