首页 > 解决方案 > 致命错误:未捕获的 Requests_Exception:cURL 错误 28:连接在 10009 毫秒后超时

问题描述

我尝试运行用 PHP 编写的第三方 API,但是当我尝试运行时,它给了我一个错误

致命错误:未捕获的 Requests_Exception:cURL 错误 28:连接在 D:\xampp\htdocs\ArchivLearn\Requests\library\Requests\Transport\cURL.php:428 10009 毫秒后超时 堆栈跟踪:#0 D:\xampp\htdocs \ArchivLearn\Requests\library\Requests\Transport\cURL.php(179):Requests_Transport_cURL->process_response('', Array) #1 D:\xampp\htdocs\ArchivLearn\Requests\library\Requests.php(381): Requests_Transport_cURL->request('http://api-core...', Array, Array, Array) #2 D:\xampp\htdocs\ArchivLearn\po_client.php(54): Requests::request('http: //api-core...', Array, Array, 'POST') #3 D:\xampp\htdocs\ArchivLearn\po_client.php(31): POClient->request('post', '/apps/any /sessi...', Array) #4 D:\xampp\htdocs\ArchivLearn\pet_details.php(12): POClient->sign_in('ka83jf466',Array) #5 {main} 在第 428 行的 D:\xampp\htdocs\ArchivLearn\Requests\library\Requests\Transport\cURL.php 中抛出

public function requestJSON($method, $path, $jsonString) {
    $timestamp  = $this->timestamp();
    $signature = $this->signature($path, $timestamp);
    $jsonString = str_replace('{accesskey}', $this->access_key, $jsonString);
    $jsonString = str_replace('{timestamp}', $timestamp, $jsonString);
    $jsonString = str_replace('{signature}', $signature, $jsonString);
    $jsonString = str_replace('{session}', $this->token, $jsonString);
    $headers = ['Content-Type' => 'application/json', 'Accept' => '*/*'];
    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => $this->host.$path,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 10,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => $method,
      CURLOPT_POSTFIELDS => $jsonString,
      CURLOPT_HTTPHEADER => $headers
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);
    if ($err) {
        error_log("requestJSON error".json_encode($err));
    }
    if ($response) {
        return json_decode($response);
    }
    return null;

}

请帮我解决这个问题。

标签: phpwordpresscurl

解决方案


推荐阅读