底层服务器问题

时间:2018-07-10 14:32:07

标签: curl networking oauth localhost ampps

我在本地服务器(AMPPS)上运行WHMCS时遇到问题。 尽管我已经将证书(来自https://curl.haxx.se/docs/caextract.html的cacert.pem)添加到了与AMPPS相同的php.ini文件夹中,并设置为证书(这工作了一段时间,但似乎还有其他问题)。

第二,我试图使用WHMCS来向使用OAuth的API发出CURL请求。我无法使用该代码获得访问令牌(是,我尝试使用多个代码),并且一直收到响应时间为-1的空白响应,但仍收到空白响应。奇怪的是,尽管存在证书问题,SSL验证状态仍为1。 这两个问题从未在另一台计算机上影响过我,并且互联网上没有其他人同时出现过这两个问题,它们似乎表明存在更大的问题。使用帮助器类向特定的API(freeagent)发送CURL请求,该类中没有其他人报告过该问题,并且其他cURL请求已成功使用我的服务器。

以下是通话代码(我使用的是“ oauth”类型):

private function call($endpoint, $type, $data=array()){
    $ch = curl_init();
    // Setup curl options
    $curl_options = array(
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 60,
        CURLOPT_USERAGENT      => 'Depot-PHP'
    );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/../cacert.pem");
    $splitBody = false;
    // Set curl url to call
    if ($type == 'oauth'){
        $curlURL = $this->oauthAccessTokenURL;
    } else {
        $curlURL = $this->apiUrl.$endpoint;
        $curl_options += array(
            CURLOPT_HTTPHEADER => array(
                'Authorization: Bearer '.$this->accessToken,
                'Accept: application/json',
                'Content-Type: application/json',
            ),
            CURLOPT_HEADER => 1
        );

        $splitBody = true;
    }

    // type of request determines our headers
    switch($type){

        case 'post':
            $curl_options = $curl_options + array(
                CURLOPT_POST        => 1,
                CURLOPT_POSTFIELDS  => json_encode($data)
            );
        break;

        case 'put':
            $curl_options = $curl_options + array(
                CURLOPT_CUSTOMREQUEST => 'PUT',
                CURLOPT_POSTFIELDS  => json_encode($data)
            );
        break;

        case 'delete':
            $curl_options = $curl_options + array(
                CURLOPT_CUSTOMREQUEST => 'DELETE',
                CURLOPT_POSTFIELDS  => $data
            );
        break;

        case 'get':
            $curlURL .= '?&'.http_build_query($data);
            $curl_options = $curl_options + array(
            );
        break;

        case 'oauth':
            $curl_options = $curl_options + array(
                CURLOPT_USERPWD    => $this->clientId.':'.$this->clientSecret,
                CURLOPT_POST       => 1,
                CURLOPT_POSTFIELDS => $data
            );
        break;

    }

    // add url
    $curl_options = $curl_options + array(
        CURLOPT_URL => $curlURL
    );

    // Set curl options
    curl_setopt_array($ch, $curl_options);

    // Send the request
    $this->result = curl_exec($ch);

    // freeagent returns location: for some responses
    if ($splitBody){
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($this->result, 0, $header_size);
        $this->result = substr($this->result, $header_size);
        $this->headers = $this->parseHeaders($header);
    }

    // curl info
    $this->info = curl_getinfo($ch);

    if ($this->debug){
        var_dump($this->result);
        var_dump($this->info);
    }

    // Close the connection
    curl_close($ch);

    return json_decode($this->result);
}

}

整个函数返回空白,有关CURL请求的信息如下:

{ [ "url" ] => string(51) "https://api.sandbox.freeagent.com/v2/token_endpoint" [ "content_type" ] => NULL [ "http_code" ] => int(0) [ "header_size" ] => int(0) [ "request_size" ] => int(0) [ "filetime" ] => int(-1) [ "ssl_verify_result" ] => int(1) [ "redirect_count" ] => int(0) [ "total_time" ] => float(0.05031) [ "namelookup_time" ] => float(0.029338) [ "connect_time" ] => float(0.050294) [ "pretransfer_time" ] => float(0) [ "size_upload" ] => float(0) [ "size_download" ] => float(0) [ "speed_download" ] => float(0) [ "speed_upload" ] => float(0) [ "download_content_length" ] => float(-1) [ "upload_content_length" ] => float(-1) [ "starttransfer_time" ] => float(0) [ "redirect_time" ] => float(0) [ "redirect_url" ] => string(0) ""

这里似乎存在某种形式的潜在问题,但不清楚是什么?任何帮助将不胜感激

0 个答案:

没有答案