2010-12-13 38 views
0
<?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'); 
?> 

L'erreur que je reçois est ceErreur lors de l'utilisation de curl pour effectuer un POST sur une certaine API. Quel est le problème?

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 

est-il une erreur dans le code? et comment le déboguer?

Répondre

1
($options + $defaults) //doesn't preserve array keys 

curl_post($url, array $post = null, array $options = array()) //$post needs to be array not null