开发者

curl_exec always returns 0?

I have this function:

function Connect($url, $post = 0, $postfields = '') 
{
    $ch = curl_init();
    if($post > 0) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    } 
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/joomla-cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/joomla-cookie.txt');
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $exec = curl_exec($ch);
    if($exec) { return $exec; } else { return 0; }
}

I call it like that Connect($host)

开发者_如何学JAVAAnd it always return 0...


Try setting CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST to false. that should do the trick.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);


Check if there was an error with the request after curl_exec:

if(curl_errno($ch)){
    echo 'Curl error: ' . curl_error($ch);
}

That will provide you with enough info to know if there was a error with the request. If there was no error, you can check the request sent after curl_exec so you can double check that everything sent is in place:

print_r(curl_getinfo($ch));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜