简体   繁体   中英

cURL with PHP - HTTP cURL to HTTPS

I have the following bit of PHP, it works locally (via apache and localhost) but not on my hosting - $response is always empty:

function get_data($url) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }

    $api_key = 'my_api_key'; 

    $randomString = generateRandomString(10);
    $endLabel = sha1(md5($randomString));
    $user_id = $endLabel;

    $amount_doge = '5'; 

    $url = "https://dogeapi.com/wow/?api_key=".$api_key."&a=get_new_address&address_label=".$user_id;
    $response = get_data($url);

I wondered if this could be because I'm hosted on HTTP (no SSL option) and I'm calling a HTTPS domain? If so, is there a way around this? I've tried curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); but it doesn't seem to do anything :(

try to use echo curl_error($ch) after $data = curl_exec($ch); to see what curl says it wil lreport you what happened

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM