php - curl_exec returns false, curl_error returns empty
滿天的星座
滿天的星座 2017-05-24 11:33:47
0
3
1974

The return value of curl_exec($ch) is always false, and calling curl_errno($ch) is empty? ? ?

public function http_curl($url,$type='get',$res='json',$arr=''){
    // 初始化
    $ch=curl_init();
    // 设置参数
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_HEADER,FALSE);
    if($type == 'post'){
        curl_setopt($ch,CURLOPT_POST, true);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$arr);
    }
    $output=curl_exec($ch);
    curl_close($ch);
    var_dump($output);
    echo 'error:'.curl_errno($ch);
    if(curl_errno($ch)){
        var_dump(curl_errno($ch));
    }
    if($res == 'json'){
        return json_decode($output,true); 
    }
        return $output;
}

滿天的星座
滿天的星座

reply all(3)
龍

What should I do if my curl_init returns empty?

phpcn_u1582

Thanks for the invitation!

curl_errno($ch) You have closed the handle before, change the order and then print.

迷茫

It would be strange to still get errors after closing the connection. . Get the error before curl_close

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template