Warning: curl_error(): 1 is not a valid cURL handle resource错误

在微信开发获取acces_token过程中使用到PHPcurl采集函数遇到的警告错误:

Warning: curl_error(): 1 is not a valid cURL handle resource in xxxx line xxx

原始代码如下:

    function getWXAccessToken(){
        //1.请求url地址
        appid = 'APPID';//私有的,不发出来了appSecret = 'APPSECRET';//私有的,不发出来了
        url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".appid."&secret=".appSecret;
        //2.初始化ch = curl_init();
        //3.设置参数
        curl_setopt(ch, CURLOPT_URL,url);
        curl_setopt(ch, CURLOPT_RETURNTRANSFER, 1);
        //4.调用接口res = curl_exec(ch);
        //5.关闭curl
        curl_close(ch);
        if(curl_errno(ch)){
            var_dump(curl_error(ch));
        }
        arr = json_decode(res, true);
        var_dump($arr);
    }

经过查找问题在于我在关闭curl后又再次使用了$ch,关闭一个cURL会话会释放所有资源,cURL句柄$ch也会被释放,所以后面再使用$ch时会报错。将curl_close($ch)函数放在最后就好了。

Warning: curl_error(): 1 is not a valid cURL handle resource错误

原文链接:https://beltxman.com/1425.html,若无特殊说明本站内容为 行星带 原创,未经同意禁止转载。

Warning: curl_error(): 1 is not a valid cURL handle resource错误”上有 5 条评论;

    1. 这个可能性很多哦,亲,按照官网demo一步步来就好啦,具体看代码。

评论已关闭。

Scroll to top