cURL:根据HTTPS对HTTP的请求拒绝连接

时间:2018-06-18 04:02:17

标签: php http curl https

我尝试使用php中的cURL从HTTPS连接向HTTP发送api请求。但每次我得到Failed to connect to MY_URL: Connection refused

这是我的代码

<?php

$tok_url = "URL";
        $token_post = array(
            'username' => "username",
            'password' => "password"
        );

        $curl_log = fopen("malinda/curl.txt", 'rw');

        $curl = curl_init();
        $options = array(
            CURLOPT_PORT => "8069",
            CURLOPT_URL => $tok_url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_SSL_VERIFYPEER => 0,
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_VERBOSE         => 1,
            CURLOPT_STDERR          => $curl_log,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => $token_post,
            CURLOPT_HTTPHEADER => array("cache-control: no-cache")
        );

        curl_setopt_array($curl, $options);
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);

        print_r($err);

        if ($err) {
            return false;
        } else {
            return json_decode($response);
        }

此外,我无法找到错误日志。

我该如何解决这个问题。

0 个答案:

没有答案