首页 > 解决方案 > php中的异步Curl请求给出了错误的请求

问题描述

使用 PHP 7.3.14 版本在暂存中工作 不适用于生产环境 PHP 7.1.12 Curl 调用响应是 400 错误请求。我的代码

$url = $this->_CI->config->item('app_base_url') . $uri;
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'ABODE-API-KEY:' . $this->_key,
          //  'Cookie:' . $this->_CI->input->get_request_header('Cookie', true),
          //  'X-Device-Id:' . $this->_CI->input->get_request_header($this->_CI->config->item('cookie_device_id_name'), true)
        ));
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 1);
        //curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

        if ($method == 'post') {
            curl_setopt($curl, CURLOPT_POST, true);
        } else if ($method == 'put') {
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
        } else if ($method == 'delete')
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
        else if ($method == 'patch') {
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
        } else
            curl_setopt($curl, CURLOPT_HTTPGET, true);

        $response = curl_exec($curl);

        if ($rollbar_log === true)
            $this->_CI->mlog->critical("Error: Response from asyn curl call URL:" . $url . "KEY:" . $this->_key . " Response:" . print_r($response, true));

        if (empty($response)) {
            $error = curl_error($curl);
            log_message('error', "Error from asyn curl call" . print_r($error, true));
            $this->_CI->mlog->critical("Error: asyn curl call " . $this->_key . " Error:" . print_r($error, true));
            curl_close($curl);
            return;
        }
        curl_close($curl);
    }

获取响应错误请求 400

标签: phpphp-curl

解决方案


推荐阅读