美文网首页php开发技巧
php通curl请求第三方API返回false处理

php通curl请求第三方API返回false处理

作者: 顶尖少爷 | 来源:发表于2024-03-28 09:51 被阅读0次

    php使用curl请求

        public function  postRequest($payload){
            $ch = curl_init($postUrl);
            // 设置curl选项,包括请求方式、请求参数、header等
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
            ));
            // 执行请求,获取返回结果
            $response = curl_exec($ch);
            // 关闭curl资源
            curl_close($ch);
            // 处理返回结果
            return $response;
        }
    

    现象说明

    打印$response 是false

    处理流程

    1.打印错误code 增加:
    errno = curl_errno(ch);
    var_dump($errno);
    2.执行查看返回的code 如果77 则是因为证书的问题

    1. 重新配置证书
    2. 重启php-fpm

    相关文章

      网友评论

        本文标题:php通curl请求第三方API返回false处理

        本文链接:https://www.haomeiwen.com/subject/hysutjtx.html